Jump to content

Download a BLOB from MySQL


$username

Recommended Posts

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";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.