Hi all
I am using the following code to allow a user to download an image file via link on my website but each time I download the file and open it on my computer, it says it is corrupt and cannot be open. I have proven that the image on the server is not corrupt as I can view it via the browser directly.
switch($file_extension){
case "gif":
$ctype="image/gif";
break;
case "png":
$ctype="image/png";
break;
case "jpeg":
case "jpg":
$ctype="image/jpg";
break;
default:
$ctype="application/force-download";
break;
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($filepath)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filepath));
readfile($filepath);
exit();
What in the code above would cause my image file to be corrupt when I download it?
Thanks for reading.
Doug