amirelgohary1990 Posted June 3, 2023 Share Posted June 3, 2023 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); Quote Link to comment https://forums.phpfreaks.com/topic/316935-cannot-read-pdf-with-php/ Share on other sites More sharing options...
requinix Posted June 4, 2023 Share Posted June 4, 2023 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 Quote Link to comment https://forums.phpfreaks.com/topic/316935-cannot-read-pdf-with-php/#findComment-1609369 Share on other sites More sharing options...
amirelgohary1990 Posted June 4, 2023 Author Share Posted June 4, 2023 (edited) 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 June 4, 2023 by amirelgohary1990 Quote Link to comment https://forums.phpfreaks.com/topic/316935-cannot-read-pdf-with-php/#findComment-1609373 Share on other sites More sharing options...
requinix Posted June 4, 2023 Share Posted June 4, 2023 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? Quote Link to comment https://forums.phpfreaks.com/topic/316935-cannot-read-pdf-with-php/#findComment-1609374 Share on other sites More sharing options...
amirelgohary1990 Posted June 4, 2023 Author Share Posted June 4, 2023 (edited) 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 June 4, 2023 by amirelgohary1990 Quote Link to comment https://forums.phpfreaks.com/topic/316935-cannot-read-pdf-with-php/#findComment-1609375 Share on other sites More sharing options...
requinix Posted June 4, 2023 Share Posted June 4, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/316935-cannot-read-pdf-with-php/#findComment-1609376 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.