473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

error while downloading file getting binary data instead of the actually file

getting error while downloading file, getting binary data to the browser instead of the actually file, specially pdf files. im using BLOB data type in mysql filed.

v?—x¢b(‏°®ه– ç‏zٍڈà÷µï½zTَکêùQïىxùSَ–‏jîآ·×Yï¹oف5KK÷¾oصتم ح+¾¦œ:و†ƒloوnأ"گ ±Oّ•زـ¦§w8^uLٹé†-ئûpfچâ+أجشƒœر د؛-ںe•ؤ…¬RH¦ hْDyے#½=@'X'§¾ذXœtz”†رص0âLوٍ›“ء²{÷ڈے ½}f؛ِâB¦ک*ژ¯“كگyeطPeüpy,¥¼تِŒً•MR±wگCي¢âٹ‘ ¬}Fzى3¢e¾NAو^4è¬{j=¤ر³جسâل<¶–5Mz&@+*MYN1ُ¨C ںq)زêذش£M nj*]T‡à*×h0ï3D¤*6غإQ.µg¬€ء¥w«ي|م+s“çكûmٍاe¯Œغ½وؤ~لà… ½ں$/‡ھ(!·@‡]µظtحîز4»CQeں[°ظ5گ+è’ہù4›MQd™@ں|‡فژd؟×ë×F*xز‘ ¹’پ÷i·?ù×ـسخ½Mأ}ق¸َOe$ِ à'ظgءl”ƒ=fRن(rإهـPy¨2ش2ج:طQî49œt رA3kfفذ’){¯'7ذE=»نx¾ةLb|‘شاـ×s ل‡ةأجô‰—ثSùy¦y†uھc>*ا/’›Zç9Vٍ·بش&¸ةq“s؟Yعlzگïگ_v¼ئ؟!؟د h=لّ’ےJ‏تْ…£ںبb÷U;Lآڑ›eڑƒ¨}كFپ ں›Uنvi>“]¤vçW†•Bڑˆˆ´!ج=¥4†é1حز ہحٹ‚é?“ل¢qع¬ ض4‹فلtڑgؤbوT§ةŒEچ8“س©#ôںآ‹EW9—ھr ‘8ژ§¦z$»±¸SW •¨xضث؛i›©سؤ™:pا¾YهسaکؤvC«صژkœچ “ژr\îW"Tùؤ'œ¥<غàû<§«،«ئ¶ —ًيFل¥رکً³ظ(WVتG{i®> stream xœه]ëڈeإqXXVثs1ث‚¹ ;†¹ôûAâDٹEت7[Hùùd'N"ضر’ے_JUWَُô¹sg¦w±#ygخمVWuWWW?~Oâ(صAàü‏ ةف¯çüك»éد‡ےxW‏ë®4ٌ£;Hkز؟ے_ؤƒSر~ü÷»ےQ*pئ¨C0 ؛{,=ƒ=َù‰ég”qً?™ïH،l{[:گJ›‏Uي¢؛ٍص,أوm)¤>ٌ6ف*ے°R:^ùêî[ثٹ3¢¾m…ƒضŒ‡ إVeززF{{0BM*ˆڑں°îùخVيئ[ّ هYPüG6Eàغn{[£´Rآدù•د¥·ءىفس¾¸÷*‹~÷=ِ/

here is my php code for downloading

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4.  
  5. $company =$_GET['company'];
  6.  
  7. // Make sure an ID was passed
  8. if(isset($_GET['id'])) {
  9. // Get the ID
  10. $id = intval($_GET['id']);
  11. // Make sure the ID is in fact a valid ID
  12. if($id <= 0) {
  13. die('The ID is invalid!');
  14. }
  15. else {
  16. // Connect to the database
  17. $dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf');
  18. if(mysqli_connect_errno()) {
  19.     die("MySQL connection failed: ". mysqli_connect_error());
  20. }
  21.  
  22. // Fetch the file information
  23. $query = "
  24.     SELECT mime, name, size, data
  25.     FROM $company
  26.     WHERE id = $id";
  27. $result = $dbLink->query($query);
  28.  
  29. if($result) {
  30.     // Make sure the result is valid
  31.     if($result->num_rows == 1) {
  32.     // Get the row
  33.         $row = mysqli_fetch_assoc($result);
  34.  
  35.         // Print headers
  36.         header("Content-Type: ". $row['mime']);
  37.         header("Content-Length: ". $row['size']);
  38.         header("Content-Disposition: attachment; filename=". $row['name']);
  39.  
  40.         // Print data
  41.         echo $row['data'];
  42.     }
  43.     else {
  44.         echo 'Error! No image exists with that ID.';
  45.     }
  46.  
  47.     // Free the mysqli resources
  48.     @mysqli_free_result($result);
  49.     }
  50.     else {
  51.     echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
  52.     }
  53.     @mysqli_close($dbLink);
  54.     }
  55.     }
  56.     else {
  57.     echo 'Error! No ID was passed.';
  58.     }
  59.     ?>
  60.  
Aug 29 '13 #1
0 1383

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: projecktzero | last post by:
Well, I've managed to get an image into a postgre database, but now I'm having trouble getting it out. #! /usr/bin/env python from pyPgSQL import PgSQL def main(): connectdb =...
4
by: Igor Shulgin | last post by:
Hi! What is standard and direct way (within Oracle 9.2 stored procedures) for writing binary data from Oracle to external file on disk? We have tried to use UTL_FILE package, but it operates on...
3
by: Billy Smith | last post by:
I'm trying to write a little utility that will write some binary data to a file via a javascript and Windows Script Host under Windows XP. The only way to do this that I can find is to convert...
22
by: David Warner | last post by:
Greetings! I am working on a C app that needs to read print files generated by lp that contain HP LaserJet PCL codes. If the PCL contains binary data to define a bit map to be printed on the...
7
by: Ryan Liu | last post by:
Hi, I want to backup database to a text file. There are binary columns. I read byte from the column and use ASCII encoding convert it to string and write to a text file. But there are bytes...
3
by: nigel | last post by:
Hi, I'm using VBA to export data from a table direct to a CSV file DoCmd.TransferText acExportDelim, , "ExportTable", filePath this produced a file with COMMA separated values,...
0
by: Carl Forsman | last post by:
I have some binary data encoded as Base64 encoding in an XML element like this: <data>TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx</data> how can I extract this data -...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.