Hello,
I've already posted this message on the 'database' forum, but didn't get a response, so I'm trying again here.
Basically, I can upload an image to the mysql database without a problem (storing it as type blob). However, I'm having great difficulty coding it so that a user can download it to their hard-drive via a link.
Here is my basic code that executes once the user clicks the download link:
$sql = "SELECT image, image_type, image_name, image_size FROM Designs WHERE design_id=$design_id";
$result = @($sql, $connect_ID);
$data = @mysql_result($result, 0, "image"); // the blob info
$name = @mysql_result($result, 0, "image_name");
$size = @mysql_result($result, 0, "image_size");
$type = @mysql_result($result, 0, "image_type");
header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
To make sure the variables were set correctly, I printed out $name, $size, and $type and they read as follows: car.jpg, 2256, image/pjpeg.
When I click the download link, I do get a "Save as" window (link I want), but it attempts to save the file as type: HTML (instead of jpg). I think the problem is the 'image/pjpeg' Content-type, since when I hard-code 'image/jpeg' into the Content-type header the save as window does list jpeg as the file type.
If I do go ahead and hard-code the Content-type as 'image/jpeg' and save the image to my hard-drive it works and does appear on my desktop. However, when I try to open it in windows preview-pane, Paint, or I.E., it isn't viewable. But, if I open it in Photoshop it displays fine. The only thing I can think is that it must be something I'm not doing correctly in the headers.
Any help you can provide would be greatly appreciated as I'm trying to complete a project and the user must be able to view downloaded image files in a browser after having been save to their hard-drive (not all users will have access to Photoshop).
Thanks a lot!!