1

PDF file shown symbols on live server while fetched from database, but displayed correctly on local sever. I don’t know exactly what I am doing wrong.

Below is my code

<?php
    if(ISSET($_REQUEST['file'])){
        $file = $_REQUEST['file'];

        // Add header to load pdf file
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' .$file. '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
// @readfile($file);
    @readfile("files/".$file);
    }
?>

Here is a sample displayed symbol

  • suggestion: force download instead. Try using [this](https://stackoverflow.com/questions/8485886/force-file-download-with-php-using-header) – Ken Lee May 28 '22 at 06:59
  • Do you have a navigator pdf reader? CAN you get it by removing headers one by one? – JoelCrypto May 28 '22 at 07:08
  • 1
    Don't use [`Content-Transfer-Encoding`](https://stackoverflow.com/questions/7285372/is-content-transfer-encoding-an-http-header). – Olivier May 28 '22 at 07:22
  • And check the value of the `Content-type` header returned by the live server. – Olivier May 28 '22 at 07:22
  • @Ken Lee, I needed to view the PDF and not to download it. Thank you. – JustSp3cial May 28 '22 at 09:21
  • Thanks so much at @K J, the file itself is save on a folder called "files", while only the path is save in the database. My concern is that, this works fine on local server without any issues. – JustSp3cial May 29 '22 at 05:26

0 Answers0