php - pdf file not downloading -
i using next code start downloading pop-up download not opening. instead, shows binary format of pdf file. it's working on local server not working hosted server.
$file = '../notes/chapter01.pdf'; if (file_exists($file)) { header('content-description: file transfer'); // header('content-type: application/octet-stream'); header('cache-control: public'); // needed i.e. header('content-type: application/pdf'); header('content-disposition: attachment; filename='.basename($file)); header('content-transfer-encoding: binary'); header('expires: 0'); //header('cache-control: must-revalidate'); header('pragma: public'); header('content-length: ' . filesize($file)); ob_end_clean(); flush(); readfile($file); exit; } else { die('error: file not found.'); }
this code works.
$file = '../notes/chapter01.pdf'; $mime_type = 'application/pdf'; $filesize = filesize( $file ); header( "content-type:" . $mime_type ); header( "content-length:" . $filesize ); header( "content-disposition: attachment; filename=" . $file ); header( "cache-control: private, max-age=15" ); @readfile( $file );
hope helps.
php
No comments:
Post a Comment