I'm writing a script to download files that are not stored within the htdocs area of my site. I can display the files, and seem to download them - but then when i try and open them on my computer - they won't open any more! I'm trying it with jpg images at the moment..
So there is obviously something wrong with my download script! I'm fairly new to PHP. The function i'm using to download the file is give below
function DownloadFile($filename)
{
// Verify filename
if (empty($filename) || !file_exists($filename))
{
return FALSE;
}
// Create download file name to be displayed to user
$saveasname = basename($filename);
header('Content-Disposition: attachment; filename="'.$saveasname.'"');
Header("Content-Length: ".filesize($filename));
Header("Content-Type: application/x-download");
Header("Content-Disposition: attachment; filename=\"".rawurlencode($saveasname)."\"");
// Output file
readfile($filename);
// Download successfully started
die();
}
Help, please!