Jump to content

Cannot read pdf with PHP


Recommended Posts

When I try to display  PDF , not working when pdf contains path, just working if the file is in the same index

This Works 
<a href="myfile.pdf" target="_blank">View PDF</a>

The below not working .. ERROR The requested URL was not found on this server.
<a href="admin/assets/cvs/myfile.pdf" target="_blank">View PDF</a>

I am sure that the path is right and I tested with .png extensions.

 

Also I tried to use header function to display PDF with PHP but got also error even if the file in the same directory index Failed to load PDF document.

 

$fileName = "myfile.pdf";
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' .urlencode($fileName). '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($fileName));
header('Accept-Ranges: bytes');
@readfile($fileName);

Link to comment
Share on other sites

No, the path is not correct. Because if it were then all this would be working, wouldn't it?

If you want to link to the PDF in your HTML then read this and give it another try:
https://stackoverflow.com/questions/2005079/absolute-vs-relative-urls

If you want to read the PDF with PHP code then read this one and give it another try:
https://phpdelusions.net/articles/paths

Link to comment
Share on other sites

8 hours ago, requinix said:

No, the path is not correct. Because if it were then all this would be working, wouldn't it?

If you want to link to the PDF in your HTML then read this and give it another try:
https://stackoverflow.com/questions/2005079/absolute-vs-relative-urls

If you want to read the PDF with PHP code then read this one and give it another try:
https://phpdelusions.net/articles/paths

Hello,

When I type admin/assets/cvs/myimage.png  It's working

but when I type a pdf admin/assets/cvs/myfile.pdf  not working

That's why I assumed that the path should be right 

PDF only reads with me if the file in the same folder index like this <a href="myfile.pdf" target="_blank">View PDF</a> This working

Edited by amirelgohary1990
Link to comment
Share on other sites

Either the path is wrong or the file is not where you think it is. I don't know what else to tell you.

 

17 hours ago, amirelgohary1990 said:

This Works 
<a href="myfile.pdf" target="_blank">View PDF</a>

The below not working .. ERROR The requested URL was not found on this server.
<a href="admin/assets/cvs/myfile.pdf" target="_blank">View PDF</a>

If the first one works then why do you want to change it?

Link to comment
Share on other sites

6 minutes ago, requinix said:

Either the path is wrong or the file is not where you think it is. I don't know what else to tell you.

 

If the first one works then why do you want to change it?

I need to store PDFs in a folders, not keep random in the same index root,
Actually it's very strange either path and file 100% are right I double checked

Edited by amirelgohary1990
Link to comment
Share on other sites

You and your server disagree about where the file is. You put it in the place you want it, and you know what the path is, but what you're telling the server is not the same thing.

So let's see if we can't just resolve this immediately:

1. What is the full, absolute path to the PDF file as a file? Not a URL. I mean where it exists on your server - for example, /var/www/mywebsite/admin/assets/cvs/myfile.pdf
2. What is the full, absolute path to the PHP script you want to use to download the PDF file? If you still want one. You don't have to have it.
3. In case it's not obvious from those answers, what is the full, absolute path of where your website files are hosted? For example, /var/www/mywebsite.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.