roywebdesign Posted September 7, 2011 Share Posted September 7, 2011 Hello all, I'm designing an upload file section for a home medical company. So far it has been going great, I am uploading files and they're being successfully inserted into my MYSQL Table. However, my issue is when I download the files they claim to be corrupted and unusable. If I save the PDF files to my desktop they won't open at all, they claim to be corrupted. If I download a JPG and then open it in photshop it warns me the file may be corrupted, knowing it is not I clicked "yes". The jpg actually opens and looks like the image, however about 50 pixels on the bottom get cut off and look like a messy TV screen, if that makes sense. Wondering if anyone has had this similar issue, the uploading part is not the issue - just downloading the files. My Upload Form Code: <p><a href="upload.php">Upload a File</a> <a href="../admin/admin.php">Back to Control Panel</a></p> <form action="add_file.php" method="post" enctype="multipart/form-data"> <input type="file" name="uploaded_file"><br> <input type="submit" value="Upload file"> </form> <p> <a href="list_files.php">See all files</a> </p> My Add File Code (This is working fine but may cause issues with downloading?) <?php // Check if a file has been uploaded if(isset($_FILES['uploaded_file'])) { // Make sure the file was sent without errors if($_FILES['uploaded_file']['error'] == 0) { // Connect to the database $dbLink = new mysqli('localhost', 'vzimbel_user', 'webdesign1', 'vzimbel_db'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Gather all required data $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']); $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']); $data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name'])); $size = intval($_FILES['uploaded_file']['size']); // Create the SQL query $query = " INSERT INTO `file` ( `name`, `mime`, `size`, `data`, `created` ) VALUES ( '{$name}', '{$mime}', {$size}, '{$data}', NOW() )"; // Execute the query $result = $dbLink->query($query); // Check if it was successfull if($result) { echo 'Success! Your file was successfully added!'; } else { echo 'Error! Failed to insert the file' . "<pre>{$dbLink->error}</pre>"; } } else { echo 'An error accured while the file was being uploaded. ' . 'Error code: '. intval($_FILES['uploaded_file']['error']); } // Close the mysql connection $dbLink->close(); } else { echo 'Error! A file was not sent!'; } // Echo a link back to the main page echo '<p>Click <a href="upload.php">here</a> to go back</p>'; ?> My List File Code (This is working fine also, but does contain the link that I click when I want to download a file) <?php $dbLink = new mysqli('localhost', 'vzimbel_user', 'webdesign1', 'vzimbel_db'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Query for a list of all existing files $sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`'; $result = $dbLink->query($sql); // Check if it was successfull if($result) { // Make sure there are some files in there if($result->num_rows == 0) { echo '<p>There are no files in the database</p>'; } else { // Print the top of a table echo '<table width="100%"> <tr> <td><b>Name</b></td> <td><b>Mime</b></td> <td><b>Size (bytes)</b></td> <td><b>Created</b></td> <td><b> </b></td> </tr>'; // Print each file while($row = $result->fetch_assoc()) { echo " <tr> <td>{$row['name']}</td> <td>{$row['mime']}</td> <td>{$row['size']}</td> <td>{$row['created']}</td> [u][b]<td><a href='get_file.php?id={$row['id']}'>Download</a></td>[/b][/u] </tr>"; } // Close table echo '</table>'; } // Free the result $result->free(); } else { echo 'Error! SQL query failed:'; echo "<pre>{$dbLink->error}</pre>"; } // Close the mysql connection $dbLink->close(); ?> And here is my Get File page. This is where my problem lies. (I think) <?php // Make sure an ID was passed if(isset($_GET['id'])) { // Get the ID $id = intval($_GET['id']); // Make sure the ID is in fact a valid ID if($id <= 0) { die('The ID is invalid!'); } else { // Connect to the database $dbLink = new mysqli('localhost', 'vzimbel_user', 'webdesign1', 'vzimbel_db'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Fetch the file information $query = " SELECT `mime`, `name`, `size`, `data` FROM `file` WHERE `id` = {$id}"; $result = $dbLink->query($query); if($result) { // Make sure the result is valid if($result->num_rows == 1) { // Get the row $row = mysqli_fetch_assoc($result); // Print headers header("Content-Type: ". $row['mime']); header("Content-Length: ". $row['size']); header("Content-Disposition: attachment; filename=". $row['name']); // Print data echo $row['data']; } else { echo 'Error! No image exists with that ID.'; } // Free the mysqli resources @mysqli_free_result($result); } else { echo "Error! Query failed: <pre>{$dbLink->error}</pre>"; } @mysqli_close($dbLink); } } else { echo 'Error! No ID was passed.'; } ?> Thanks for any help that anyone can provide, this issue is really causing some stress and hurting my sleep at night! Can't figure out why this won't work, it's literally the last step in completing this website. Please let me know if you need any other information regarding this issue. Thanks, - Mike Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 8, 2011 Share Posted September 8, 2011 What's the definition of your `data` column? What does a phpinfo() statement show for the magic_quotes_runtime setting? Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1266675 Share on other sites More sharing options...
roywebdesign Posted September 8, 2011 Author Share Posted September 8, 2011 Hello and thanks for the help! My magic_quotes_runtime is Local Value = "Off" and Master Value = "Off". My data type in my table is set to mediumblob, I've also tried longblob. Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1266879 Share on other sites More sharing options...
PFMaBiSmAd Posted September 8, 2011 Share Posted September 8, 2011 Save one of the 'corrupted' download files and open it using your programming editor and see if there is anything, like a php error message, in it. Also, if your database management tool permits it, download/save the contents of your `data` column as a file and see if the actual data saved in the database table is valid or not. What are the sizes of the .pdf and .jpg files that don't work and what does a phpinfo() statement show for the output_buffering setting? Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1266925 Share on other sites More sharing options...
roywebdesign Posted September 8, 2011 Author Share Posted September 8, 2011 Hello again PFMaBiSmAd, If I open one of the jpg's I get the following in my text editor: <IMG SRC="../../xx.jpg" WIDTH="720" HEIGHT="540" BORDER="0" ALT=""> The PDF's are alittle different, I'll post what I gave back but it is pretty long. It actually took all the HTML with it. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> VZimbel </title> <link rel="stylesheet" href="../styles.css" type="text/css" /> <!--[if IE 6]> <link href="main-ie6-global.css" rel="stylesheet" type="text/css" /> <![endif]--> <!--[if IE 7]> <link href="main-ie7-global.css" rel="stylesheet" type="text/css" /> <![endif]--> <!--[if IE 8]> <link href="main-ie8-global.css" rel="stylesheet" type="text/css" /> <![endif]--> </head> <body> <div id="content"> <div id="topnav" class="clearfix"> <div class="nav"> <ul> <li><a href="index.php">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </div> <div class="slogan"> <p> <a href="VZimbel.com - Home Medical Equipment Consulting Company">VZimbel.com - Home Medical Equipment Consulting Company</a></p> </div> </div> <div id="header6" class="clearfix"> <div class="title"> <h1>Vianna Zimbel Consulting</h1> </div> <div class="mainnav"> <ul> <li class="home"><a href="http://www.vzimbel.com/draft/index.php">Home</a></li> <li class="procedure"><a href="http://www.vzimbel.com/draft/procedure.php">Procedure Manual</a></li> <li class="consulting"><a href="http://www.vzimbel.com/draft/consulting.php">Consulting Services</a></li> <li class="company"><a href="http://www.vzimbel.com/draft/company.php">Company Profile</a></li> <li class="members"><a href="http://www.vzimbel.com/draft/admin/login.php">Members Only</a></li> <li class="links"><a href="http://www.vzimbel.com/draft/draft/links.php">Links</a></li> <li class="news"><a href="#">News Feed</a></li> <li class="contact"><a href="#">Contact</a></li> </ul></div> <div class="about"> <h1><br />About VZimbel</h1> <p class="aboutvzimbel">Greetings from Vianna Zimbel Consulting. We are a home medical equipment consulting company. While our main goal has been to help companies through the accreditation process as easily and inexpensively as possible, we also provide products and services, such as patient education materials, survey-proven customized policy and procedure manuals, regulatory compliance guidance, and performance improvement programs to help your home care company make the most of your resources.</p> <p class="more"><a href="#">Read More...</a></p> </div> </div> </div> </div> <div id="mainbody" class="clearfix"> <h3><br/>Admin Section</h3> <div class="longbar"><img src="../images/longbar.jpg"></div> <div class="rightpicture"></div> <div class="picture"><h4></h4> <p><a href="upload.php">Upload a File</a></p> %PDF-1.4 %âãÏÓ 14 0 obj <</Linearized 1/L 28951/O 16/E 17380/N 2/T 28624/H [ 576 201]>> endobj xref 14 14 0000000016 00000 n 0000000777 00000 n 0000000857 00000 n 0000000987 00000 n 0000001139 00000 n 0000001616 00000 n 0000002132 00000 n 0000002167 00000 n 0000002395 00000 n 0000002617 00000 n 0000002694 00000 n 0000004521 00000 n 0000007214 00000 n 0000000576 00000 n trailer <</Size 28/Prev 28613/Root 15 0 R/Info 13 0 R/ID[<88E11190253A01848A6D3E18310E6E28><47FE8249437ED2469C17B8C3FBA60EF0>]>> startxref 0 %%EOF 27 0 obj <</Length 114/Filter/FlateDecode/I 125/L 109/S 62>>stream xÚb```g``šÀÀÌÀ ËÀÇ€ ========================================================= The sizes of the files that don't work are pretty small. The JPG is 91KB. The PDF is 28KB. ========================================================= You may be on to something here with downloading the table. I downloaded the entire table and got the following: 1 nav.jpg image/jpeg 29965 8/26/2011 11:06:00 2 CETOA (PWCS) Safety Alert- Crew inHold General Notice.pdf application/pdf 28951 8/26/2011 11:12:17 5 xx.jpg image/jpeg 94179 9/4/2011 21:34:51 If I download JUST the data column, I get absolutely nothing and the file is blank. ====================== Again, thank you for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1266948 Share on other sites More sharing options...
roywebdesign Posted September 8, 2011 Author Share Posted September 8, 2011 Oh and by the way, I'm not sure were to go from here. I believe we may have isolated the problem now that we know the Data Column is empty, but how do I go about fixing such an issue? Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1266950 Share on other sites More sharing options...
PFMaBiSmAd Posted September 8, 2011 Share Posted September 8, 2011 If you open the original (the files that you uploaded) .pdf and .jpg files in your programming editor, what do they contain? Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1266955 Share on other sites More sharing options...
roywebdesign Posted September 8, 2011 Author Share Posted September 8, 2011 That I'm not sure of because I no longer have the original files. I've been working on this for days, so they must have gotten deleted. I will upload some new files and find this out for you now. Hold tight! Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1266959 Share on other sites More sharing options...
roywebdesign Posted September 8, 2011 Author Share Posted September 8, 2011 Alright, the original PDF before I download it looks like this: %PDF-1.4 %âãÏÓ 83 0 obj <</Linearized 1/L 89386/O 85/E 19396/N 22/T 87679/H [ 716 491]>> endobj xref 83 21 0000000016 00000 n 0000001207 00000 n 0000001288 00000 n 0000001418 00000 n 0000001623 00000 n 0000002166 00000 n 0000002325 00000 n 0000002360 00000 n 0000002406 00000 n 0000002628 00000 n 0000002871 00000 n 0000002948 00000 n 0000003766 00000 n 0000004278 00000 n 0000004506 00000 n 0000005047 00000 n 0000005275 00000 n 0000007968 00000 n 0000017902 00000 n 0000018268 00000 n 0000000716 00000 n trailer <</Size 104/Prev 87668/Root 84 0 R/Info 82 0 R/ID[<94C2C41F1DCFF95F6FC7F220A7C816FF><05DCE29BD81313488CDDF496777B2FE4>]>> startxref 0 %%EOF 103 0 obj <</Length 402/Filter/FlateDecode/I 572/L 556/S 487>>stream xÚb```"Y¦‡üÀÏÀ „,¡bíÛ˜w0LÈü°jÿ£I±b?Äml$<|ûPÑçA‰/ŒaCùŽ ,‹«’£¾¨¾÷}ïÚê°m{ Ú™”‚ fîÍ*ä³<É&±Õ¢MðØVÓÉ“´ÝY\[¶©È¹ÓRáP¶ØrCQ³Nžd—ÕN‡J¸j—ÃXZ$Ü¥®\óóXãÌñ¤NduG¢Lvp¤¥ÒÔBåÞ¬lu• uŠ-…k}Sžt…1è3]¹f΄G2Å“xÔ6f!)9³ÍâÖÉ“|@['O’qî+rl¹¦ë7à The original JPG before I download it looks like complete non-sense in a text editor. Just a bunch of symbols and stuff that I cannot copy paste. If I try to all I am able to past is this: ÿØÿà =============================================================== Ok, now once I download the PDF and look at it in a text-editor I see: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> VZimbel </title> <link rel="stylesheet" href="../styles.css" type="text/css" /> <!--[if IE 6]> <link href="main-ie6-global.css" rel="stylesheet" type="text/css" /> <![endif]--> <!--[if IE 7]> <link href="main-ie7-global.css" rel="stylesheet" type="text/css" /> <![endif]--> <!--[if IE 8]> <link href="main-ie8-global.css" rel="stylesheet" type="text/css" /> <![endif]--> </head> <body> <div id="content"> <div id="topnav" class="clearfix"> <div class="nav"> <ul> <li><a href="index.php">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </div> <div class="slogan"> <p> <a href="VZimbel.com - Home Medical Equipment Consulting Company">VZimbel.com - Home Medical Equipment Consulting Company</a></p> </div> </div> <div id="header6" class="clearfix"> <div class="title"> <h1>Vianna Zimbel Consulting</h1> </div> <div class="mainnav"> <ul> <li class="home"><a href="http://www.vzimbel.com/draft/index.php">Home</a></li> <li class="procedure"><a href="http://www.vzimbel.com/draft/procedure.php">Procedure Manual</a></li> <li class="consulting"><a href="http://www.vzimbel.com/draft/consulting.php">Consulting Services</a></li> <li class="company"><a href="http://www.vzimbel.com/draft/company.php">Company Profile</a></li> <li class="members"><a href="http://www.vzimbel.com/draft/admin/login.php">Members Only</a></li> <li class="links"><a href="http://www.vzimbel.com/draft/draft/links.php">Links</a></li> <li class="news"><a href="#">News Feed</a></li> <li class="contact"><a href="#">Contact</a></li> </ul></div> <div class="about"> <h1><br />About VZimbel</h1> <p class="aboutvzimbel">Greetings from Vianna Zimbel Consulting. We are a home medical equipment consulting company. While our main goal has been to help companies through the accreditation process as easily and inexpensively as possible, we also provide products and services, such as patient education materials, survey-proven customized policy and procedure manuals, regulatory compliance guidance, and performance improvement programs to help your home care company make the most of your resources.</p> <p class="more"><a href="#">Read More...</a></p> </div> </div> </div> </div> <div id="mainbody" class="clearfix"> <h3><br/>Admin Section</h3> <div class="longbar"><img src="../images/longbar.jpg"></div> <div class="rightpicture"></div> <div class="picture"><h4></h4> <p><a href="upload.php">Upload a File</a></p> %PDF-1.4 %âãÏÓ 83 0 obj <</Linearized 1/L 89386/O 85/E 19396/N 22/T 87679/H [ 716 491]>> endobj xref 83 21 0000000016 00000 n 0000001207 00000 n 0000001288 00000 n 0000001418 00000 n 0000001623 00000 n 0000002166 00000 n 0000002325 00000 n 0000002360 00000 n 0000002406 00000 n 0000002628 00000 n 0000002871 00000 n 0000002948 00000 n 0000003766 00000 n 0000004278 00000 n 0000004506 00000 n 0000005047 00000 n 0000005275 00000 n 0000007968 00000 n 0000017902 00000 n 0000018268 00000 n 0000000716 00000 n trailer <</Size 104/Prev 87668/Root 84 0 R/Info 82 0 R/ID[<94C2C41F1DCFF95F6FC7F220A7C816FF><05DCE29BD81313488CDDF496777B2FE4>]>> startxref 0 %%EOF 103 0 obj <</Length 402/Filter/FlateDecode/I 572/L 556/S 487>>stream xÚb```"Y¦‡üÀÏÀ „,¡bíÛ˜w0LÈü°jÿ£I±b?Äml$<|ûPÑçA‰/ŒaCùŽ ,‹«’£¾¨¾÷}ïÚê°m{ Ú™”‚ fîÍ*ä³<É&±Õ¢MðØVÓÉ“´ÝY\[¶©È¹ÓRáP¶ØrCQ³Nžd—ÕN‡J¸j—ÃXZ$Ü¥®\óóXãÌñ¤NduG¢Lvp¤¥ÒÔBåÞ¬lu• uŠ-…k}Sžt…1è3]¹f΄G2Å“xÔ6f!)9³ÍâÖÉ“|@['O’qî+rl¹¦ë7à Hopefully everything pasted over. It appears the files are exactly the same aside for the fact that the downloaded ones carry over my HTML on the top. ============================== The JPG opened as complete non-sense again, with the HTML in tact on the top like the PDF. I won't paste this code because it is just non-sense. However the following HTML is on the top of the image's code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> VZimbel </title> <link rel="stylesheet" href="../styles.css" type="text/css" /> <!--[if IE 6]> <link href="main-ie6-global.css" rel="stylesheet" type="text/css" /> <![endif]--> <!--[if IE 7]> <link href="main-ie7-global.css" rel="stylesheet" type="text/css" /> <![endif]--> <!--[if IE 8]> <link href="main-ie8-global.css" rel="stylesheet" type="text/css" /> <![endif]--> </head> <body> <div id="content"> <div id="topnav" class="clearfix"> <div class="nav"> <ul> <li><a href="index.php">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </div> <div class="slogan"> <p> <a href="VZimbel.com - Home Medical Equipment Consulting Company">VZimbel.com - Home Medical Equipment Consulting Company</a></p> </div> </div> <div id="header6" class="clearfix"> <div class="title"> <h1>Vianna Zimbel Consulting</h1> </div> <div class="mainnav"> <ul> <li class="home"><a href="http://www.vzimbel.com/draft/index.php">Home</a></li> <li class="procedure"><a href="http://www.vzimbel.com/draft/procedure.php">Procedure Manual</a></li> <li class="consulting"><a href="http://www.vzimbel.com/draft/consulting.php">Consulting Services</a></li> <li class="company"><a href="http://www.vzimbel.com/draft/company.php">Company Profile</a></li> <li class="members"><a href="http://www.vzimbel.com/draft/admin/login.php">Members Only</a></li> <li class="links"><a href="http://www.vzimbel.com/draft/draft/links.php">Links</a></li> <li class="news"><a href="#">News Feed</a></li> <li class="contact"><a href="#">Contact</a></li> </ul></div> <div class="about"> <h1><br />About VZimbel</h1> <p class="aboutvzimbel">Greetings from Vianna Zimbel Consulting. We are a home medical equipment consulting company. While our main goal has been to help companies through the accreditation process as easily and inexpensively as possible, we also provide products and services, such as patient education materials, survey-proven customized policy and procedure manuals, regulatory compliance guidance, and performance improvement programs to help your home care company make the most of your resources.</p> <p class="more"><a href="#">Read More...</a></p> </div> </div> </div> </div> <div id="mainbody" class="clearfix"> Any ideas? Seems kind of weird to me that the HTML carries over to the top of the files. PS. I pasted the first JPG's code incorrectly in my previous post. I carried it into a currently opened one so thats why I got the HTML tag for it. In reality it is just complete non-sense and symbols. Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1266969 Share on other sites More sharing options...
PFMaBiSmAd Posted September 8, 2011 Share Posted September 8, 2011 The only likely way that is occurring is if the get_file.php code contains that HTML. The only thing that should be in the get_file.php file is the php code you posted as the third piece of code at the start of this thread. get_file.php is not a web page, it is a link that is being imbedded in a html document that when clicked and requested dynamically outputs a file to be downloaded. The only thing it should output are the header() statements, followed by the file data. Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1266984 Share on other sites More sharing options...
roywebdesign Posted September 8, 2011 Author Share Posted September 8, 2011 Great! This worked for the PDF's. I can now download these and view them. For the images though, this is still not working. Once downloaded I am unable to open them in windows photo gallery, it states that it is not a supported file type, even tho it is a JPG. I am able to open these images in photoshop as I said in my original post. It gives me a warning that the file may be "damaged, corrupted or truncated", I click continue and the image appears. However about 50 pixels of the bottom of the image is blacked out. Thank you for all the help you provided, having the PDF's working now is big, because this is the main file they'll be uploading. Now I just need to fix the image downloading issue. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1266994 Share on other sites More sharing options...
roywebdesign Posted September 8, 2011 Author Share Posted September 8, 2011 Talked to my client and she needs to be able to upload microsoft word and excel files. I uploaded a word file and went to go download it. It warns me that the file may be corrupted and I click OK. It then shows me the document and it is all there. Why do I keep getting these warnings? The PDF's open with no warnings...but the JPGs, Word, Excel and everything else do... Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1267085 Share on other sites More sharing options...
PFMaBiSmAd Posted September 8, 2011 Share Posted September 8, 2011 You are probably outputting something in the get_file.php file, either before the <?php tag or after the ?> tag. Make sure there are no characters in that file outside of the <?php ?> tags and make sure that file is saved as an ANSI/ASCII encoded file and not a UTF-8 encoded file. Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1267105 Share on other sites More sharing options...
roywebdesign Posted September 9, 2011 Author Share Posted September 9, 2011 Hey again, Well I double checked and there's nothing outside my PHP tags and my file was already saved as an ANSI. Here is my code for the get_file. <?php // Make sure an ID was passed if(isset($_GET['id'])) { // Get the ID $id = intval($_GET['id']); // Make sure the ID is in fact a valid ID if($id <= 0) { die('The ID is invalid!'); } else { // Connect to the database $dbLink = new mysqli('localhost', 'vzimbel_user', 'webdesign1', 'vzimbel_db'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Fetch the file information $query = " SELECT `mime`, `name`, `size`, `data` FROM `file` WHERE `id` = {$id}"; $result = $dbLink->query($query); if($result) { // Make sure the result is valid if($result->num_rows == 1) { // Get the row $row = mysqli_fetch_assoc($result); // Print headers header("Content-Type: ". $row['mime']); header("Content-Length: ". $row['size']); header("Content-Disposition: attachment; filename=". $row['name']); // Print data echo $row['data']; } else { echo 'Error! No image exists with that ID.'; } // Free the mysqli resources @mysqli_free_result($result); } else { echo "Error! Query failed: <pre>{$dbLink->error}</pre>"; } @mysqli_close($dbLink); } } else { echo 'Error! No ID was passed.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1267321 Share on other sites More sharing options...
roywebdesign Posted September 9, 2011 Author Share Posted September 9, 2011 Hey PFMaBiSmAd, I actually got it working doing the opposite of what you wanted me to do in the last post, figured I'd let you know and anyone else who viewed this and may have the similiar problem. My file was already encoded as an ANSI, so I went ahead and switched it to UTF-8 and it worked! Quote Link to comment https://forums.phpfreaks.com/topic/246650-small-uploading-file-issue/#findComment-1267342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.