javascript - Downloaded file (using download.php) from server won't open. Why? -


i beginner. i've searched everywhere, don't know why after downloading file server through client (win 7 firefox), unable open file. i've tried png file , mp4 file. download completes, files don't open. here's script;

$dl_file = $_get['val']; //verified full path , 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 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 downloaded file won't open. corrupt? please throw more light on this. thank in advance.

after many tries, found adding 2 lines of code shown below (ob_clean, , flush) (and/or adding precheck, postcheck parameters) - worked on browsers.thanks.

if (file_exists($dl_file)) {     header('content-description: file transfer');     header('content-type: application/octet-stream');     header('content-disposition: attachment; filename="'.basename($dl_file).'"' );     header('expires: 0');     header('cache-control: must-revalidate, post-check=0, pre-check=0');     header('pragma: public');     header('content-length: ' . filesize($dl_file));     ob_clean();     flush();     readfile($dl_file);     exit; } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -