How to display PDF file using PHP

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?
Answer
Solution:
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
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: undefined array key
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.