0

I am trying to display PDF's using PHP which are stored in a folder named uploads which is located in the same folder with my php file .

this is the code I tried: (aa is the name of the pdf file)

  $file1 = '\uploads\aa.php';
      header('Content-type: application/pdf');
      header('Content-Disposition : inline; filename="' . $file1 . '"');
      header('Content-Transfer-Encoding: binary');
      header('Accept-Ranges: bytes');

   @readfile($file1);

but I get a server error :

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.

Error 500

is there any soluion for this?

1
  • 1
    Check the error logs, also `\upload` would mean the file would be in the root of the server, not in the same folder Commented Apr 14, 2021 at 16:15

1 Answer 1

1

I am taking a look at your path, and I see that you are using backslashes \ instead of a forward slash / and presuming you are not using Windows, it should be instead a /

example:

$file1 = 'uploads/aa.php';
      header('Content-type: application/pdf');
      header('Content-Disposition : inline; filename="' . $file1 . '"');
      header('Content-Transfer-Encoding: binary');
      header('Accept-Ranges: bytes');

   @readfile($file1);

more information on it here: https://www.w3schools.com/php/php_ref_filesystem.asp

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.