$username Posted August 12, 2008 Share Posted August 12, 2008 Hello All, I have been working on uploading files to MySQL and than retrieving them. They upload fine. But when I go to download them it seems to add extra info to the file. The code seems to be the first 31 lines of my index page. The code below is what I use to gather the BLOB from MySQL. Is there something wrong with this? Any help would greatly be appreciated. include 'dbopen.php'; include 'dbconnect.php'; if(isset($_GET['attachid'])) { $AttachID = $_GET['attachid']; $query611 = "SELECT AttachName, AttachType, AttachSize, AttachContent FROM attachments WHERE AttachID = '$AttachID'"; $result611 = mysql_query($query611) or die(mysql_error()); list($AttachName, $AttachType, $AttachSize, $AttachContent) = mysql_fetch_array($result611); header("Content-Disposition: attachment; filename=$AttachName"); header("Content-length: $AttachSize"); header("Content-type: $AttachType"); echo "$AttachContent"; Quote Link to comment Share on other sites More sharing options...
dbo Posted August 12, 2008 Share Posted August 12, 2008 At a quick glance everything looks okay there. Can you show the code where you insert it into the database? I seem to remember having problems with this in the past myself. I was getting corrupted image files and pulled my hair our trying to figure out why. I think I ultimately stored the data as hex and then converted it when I pulled it out... but I think an easier solution would be to use base64_encode and base64_decode to normalize the data. You'll want to encode it before insertion and then decode it when you pull it out. Quote Link to comment Share on other sites More sharing options...
$username Posted August 13, 2008 Author Share Posted August 13, 2008 So after hours have gone by I have found out that there is something with PHP and not calling the page directly. In my index.php file I have a line of code looks like this $DownloadAttachment = $_GET['dlattachment']; if ($DownloadAttachment == 1) { include_once 'downloadattachments.php'; }else{ echo ""; } So the URL that downloads the code is index.php?dlattachment=1&attlink=account&typeid=2008071433605000000&attachid=7 So when I made the URL work like this downloadattachments.php?dlattachment=1&attlink=account&typeid=2008071433605000000&attachid=7 It downloads the file just fine. I think that is crazy but it worked. I dont know if this is a bug or not. I am more so thinking that its my sloppy code. Thanks for your input. I am currently reading about base64 code. Thank you, Brett Quote Link to comment 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.