I am a beginner. I've searched everywhere, but I don't know why after downloading a file from the server through the client (Win 7 Firefox), I am unable to open the file. I've tried a PNG file and an MP4 file. The download completes, but the files don't open. Here's my script;
$dl_file = $_GET['val']; //Verified the full path and the file name gets passed here
$basename = basename($dl_file);
$ext = pathinfo($dl_file, PATHINFO_EXTENSION);
$length = sprintf("%u", filesize($dl_file));
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$basename.'');
//manually tried '.$basename.'.PNG' - DID NOT work. How to pass $ext here?
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $length);
set_time_limit(0);
readfile($dl_file);
I can't imagine why the downloaded file won't open. Is it corrupt? Please throw more light on this. Thank you in advance.