php - pdf file saved as current page source -


im trying make pdf files downloadable in website im getting current page source(html). file name correctly given file not downloading.

ive tried various fixes found on stackoverflow not helping.

ive tried addtype application/octet-stream .pdf in htaccess , forcetype. tried php fix here: how make pdf file downloadable in html link? , going through php this:

header("content-disposition: attachment; filename=filename.pdf"); header("content-type: application/pdf"); readfile("filename.pdf"); 

and linking php file, still same.

what doing wrong , information require make better sense of this?

you can have serveral mistakes check (and debug) try this

  <?php      $file = absolute_path_where_pdf_is_stored.'/my.pdf'; //replace *absolute_path_where_pdf_is_stored* path       if (file_exists($file)) {          header('content-description: file transfer');          header('content-type: application/octet-stream');          header('content-disposition: attachment; filename='.basename($file));          header('expires: 0');          header('cache-control: must-revalidate');          header('pragma: public');          header('content-length: ' . filesize($file));          readfile($file);          exit;   } else {       die("file [".$file."]" don't exists!");   }  ?> 

Comments