I'm using yii with html2pdf version 4.03 for downloading pdf documents in my project. The pdf documents consist of tables with many rows because they are reports. In my localhost, the download is fine. But when I do that in remote server, it can't be downloaded.
I used Firefox to download it. When I downloaded it, it prompted an alert message saying that I can't download because the source file cannot be read. When I force to download it (by pressing refresh button in firefox's download list), the pdf file is there. When I tried to open it, it says that the file is corrupted.
If I delete a few rows, it can be downloaded just fine. Strangely, even if I didn't delete the rows, they are still in one page. So the problem shouldn't be about "table row that doesn't fit in one page", should it?
What could be the problem? Could anyone help me with this please?
UPDATES
when I print it in browser instead of downloading, firefox prompts an error like below:
Content Encoding Error
The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.
Please contact the website owners to inform them of this problem.
Still don't know how to solve this though...
Save the generated pdf, open it in text editor, and see what error message is there.
Related
I have an internal server running PHP and an internal file directory with some work instructions pdfs for our technicians to read from. I'm trying to add a link to those pdf files so the technicians can click on the link and open the pdf in the browser.
So I have echo "' . "Work Instruction Link"
and I get Security Error: Content at http://LocalServer:50563/workInstructions.php may not load or link to file:///path/to/workInstruction.pdf
I understand the security risk of not being able to access the local files of a user from a web page, but I don't understand why I can paste the same file url into the address bar and the file will display on the web page. How are those two mechanisms different?
Is there a way to make that link work while serving it from my PHP server, or am I just going about the problem completely wrong? Is there something wrong with my formatting or syntax that I'm not catching?
I noticed that the error response does not contain the server in the file name. I don't exactly know what that means, or why that is the case.
My question is not answered by this post: html-File URL "Not allowed to load local resource in the internet browser because 1. it is asking within classic ASP which is a very different technology from PHP and 2. While it does have the same error message it does not explain how to have a link to files hosted on the same server as the webserver.
I have also tried the answer to this question: Point a link to a certain server
but it did not work for me when i try to convert "FILE://fileserver/path/to/workInstruction.pdf" to "Http://fileserver/path/to/workInstruction.pdf" I'm guessing because it's a file server and not a webserver that the pdf is located on.
To further pinpoint my question, is there a way in PHP to serve a link to a file hosted on a local server that the user can click and open a PDF in the browser?
For anyone else coming to this looking for an answer I have found this answer worked for me:
PHP-Display PDF on browser
Essentially I take the file path of the PDF I'm trying to load that I get from my fileserver and redirect to a new php file that reads the file and displays it in a new tab
The php file that contains the link will have something like this:
echo ''.$wi_num.'';
My workInstruction.php looks like this:
<?php
$filename= $_GET['filename'];
$filePath= $_GET['filepath'];
header('Content-type:application/pdf');
header('Content-disposition: inline; filename="'.$filename.'"');
header('content-Transfer-Encoding:binary');
header('Accept-Ranges:bytes');
#readfile($filePath);
?>
I've been creating a website in the same way that I usually so, where I add an article + image using HTML & PHP. The difference is that when I upload the photo, even though it displays on the web page, my folder shows an Icon instead of the image (See Below):
As the photos show on the webpage I didn't think much of it, until I tried to upload the website, where I kept getting an FTP upload error on the images. Then when loading the website, I found that none of the images were there.
I'm not sure what the problem is, but when I tried to open one of the photos in Fireworks it says, "Could not open the file. File is locked".
Does anyone know what the probelm is? I'm using the same upload method used previously.
I'm generating an excel file from PHP with PHPExcel library and when it's filled with all the data it's is automaticaly downloaded, the problem is that chrome only shows column headers without data, meanwhile firefox downloads de file correctly.
In chrome's console appears this message "Resource interpreted as Document but transferred with MIME type application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:"
Anyone may know what can cause this problem? Thanks
I am accessing this URL with my android device and the pdf download starts downloading automatically, without asking me to open the pdf vieth the pdf viewer.
This works in other websites.
I am the developer of the website. I set up the header to application/pdf. Any idea what can be the problem? Thank you.
Ok, I identified the problem and found the workaround.
It seems that the native android browser in not very intelligent. In fact, when a file is dowmloaded, the header of the file is not checked. The browser checks only the extension of the file in the url.
In my url, at the end we had /pdf, so no extension was found. By renaming the end of the url to xxx.pdf, the browser was able to recognize the file as a pdf.
I have create a CSV file in my php code,
after create CSV, I try to open the CSV using window.open(),
this will work fine all browser except IE 7 and IE 8,
in IE a new window open then it close automatically
how to solve this problem,
If I recall, Internet Explorer has a peculiar quirk when trying to open files, even if the proper MIME type is set in the header.
You may need to do the following to get the CSV to download:
Go to Tools > Internet Options
Select the Security tab, then press the Custom Level... button
Scroll down to the Downloads section, and under Automatic prompting for file downloads select Enable
Hopefully, that should resolve the issue.
Try adding the following at the beginning of your script:
header('Content-Disposition:inline');
This should direct the browser to display the file instead of prompting a download, which may be the problem.