Could use some help downloading a file
Posted: Thu Oct 27, 2005 9:46 pm
I have a function setup to download an image file from a database, however i have decided to store my images in a directory on the server instead due to size limitations of the database. I am trying to modify my function to downlaod the file from the directory but I can't seem to get it work.
Here is the simplified code for downlaoding from the db:
Now instead of saving the binary image in the database I am saving it to a directory on my server "/uploads". The only line of code I am changing is the "$file=" line but it just displaying the image instead of downloading. How do I get it to download instead? The image path is stored in the database.
Thanks for any help!
Here is the simplified code for downlaoding from the db:
Code: Select all
case 'dl':
$sql = "SELECT * FROM ".$table." WHERE image_id=".$iid;
$result = mysql_query($sql,$conn);
if (mysql_num_rows ($result)>0) {
$row = @mysql_fetch_array($result);
$filename = $row["image_name"];
$file = $row["image_path"];
$file_type = $row["image_type"];
$file_size= $row["image_size"];
if(!$file){
echo "ERROR: No image to download.";
} else {
header("Content-type: $image_type");
header("Content-length: $image_size");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Description: PHP Generated Data");
echo $file;
exit();
}
}
break;Code: Select all
$file= readfile("http://".$_SERVER['HTTP_HOST'].$row["image_path"]);