Not able to download any file in php on windows8 and ie10? - php

i have some file which generated dynamically and downloaded, code is running with no problem with other browser even on window 7 ie 10 working fine but not able two download file in window 8 ie10. i have also try to download simple text file with header text/plain which is also not downloading. it shows downloading prompt with the file name in which downloading code is there not the name i specified and nothing happen on clicking save in ie 10.working in other.
<?php
echo "this is sample text";
header('Content-type: text/plain');
//open/save dialog box
header('Content-Disposition: attachment;filename="sample.txt"');
?>

This was window 8 bug with IE 10 only that was fixed later :)

Related

PHP: wkhtmltopdf snappy (wrapper) fails

i have a problem using wkhtmltopdf with snappy.
I has installed wkhtmltopdf with homebrew on mac osx.
I use this code to display PDF in Browser:
<?php
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
require_once('snappy/autoload.php');
use Knp\Snappy\Pdf;
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
echo $snappy->getOutput('http://www.github.com');
?>
Instead of displaying the PDF in the browser, the script opens the terminal. After i click on the terminal it starts downloading the file.pdf. The file.pdf shows the correct github page.
What i am doing wrong?
And whats the best solution to manage wkhtmltopdf's binary path that the script is working on several systems (debian, windows, ..).
EDIT:
Oh sorry.. i changed attachment to inline and the browser displays the PDF.
But i must click on the terminal first..

PDFTK outputs a corrupt pdf to the browser

I am using PHP to fill a PDF form, which I would like to output to the browser. I am using the function found here: http://koivi.com/fill-pdf-form-fields to create an xfdf file. I then use the following code to fill the form and output the resulting file to the browser:
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="filename.pdf"');
passthru("/usr/local/bin/pdftk forms/pdf_form.pdf fill_form filename.xfdf output - ");
When I open the PDF created from the browser, I get an error from adobe pdf reader that says "Adobe Reader could not open 'filename.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)." Opening the same PDF in another reader does not give the error, but my users will be using acrobat.
By way of contrast, if I change my code to the following:
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="filename.pdf"');
passthru("/usr/local/bin/pdftk forms/pdf_form.pdf fill_form filename.xfdf output filename.pdf ");
I can open, read and edit the resulting PDF from the tmp folder. It seems that the 'output - ' option is somehow corrupting the PDF.
My question is this: Am I doing something wrong? Is there some piece of code that I am missing or a better way to accomplish this?
PHP version: 5.3.19; Server OS: Mac OS 10.7.5; Client OS: Mac OS
10.7.5; Browsers tested: Chrome, FireFox; Readers tested: Adobe PDF Reader, Preview; PDFTK version: 1.4.5
Use <?php ... for instance without final ?> so you are sure no final whitespace, especially newline is written after the PDF output.

Why downloaded file is not downloaded instead it is shown in browser?

I redirect the visitors in my website from page A to page B. In page B I expect users to get the downloaded PDF file (to be downloaded when page B is loading).
I have taken the code from another article (see a previous question answered here) and my code of page B is the following:
<?php
header('Content-Disposition: attachment; filename=nature.pdf');
header('Content-type: application/pdf');
$fn=fopen("/wp-content/nature.pdf","r");
fpassthru($fn);
?>
The output is not by opening a download dialog box, instead some unreadable characters are displayed in browser such as the following (I have just picked up a small sample below):
%PDF-1.4 %���� 3 0 obj <>stream x���MK1�o�+�$zIg&�� V=T�=Xo����K��i+#V�yx3��඀(BX�pW`
Server: OS Linux; PHP version: 5.2.17
The visitor -> Browser: Firefox; OS: Windows 2000
Is it possible to fail due to the old OS on client side? If not, does anybody know a solution how to force the download? Any help would be highly appreciated.
Thanks.
Try it with the Content-Length header:
ob_clean(); ob_start();
header('Content-Disposition: attachment; filename=nature.pdf');
header('Content-type: application/pdf');
header ("Content-Length: ".filesize("/wp-content/nature.pdf"));
readfile("/wp-content/nature.pdf");
exit;
There was a quirk in the really old browsers when Content-disposition was first being introduced, some of the really old browsers wouldn't show the "Save As" dialogue unless it couldn't recognize the type of file you were trying to open. Try setting the Content-type to nothing (or something unrecognizable), and see if that'll force the older browser to pop the save-as dialogue.
header('Content-type: ');
If that works, then I'd suggest adding in a line of PHP to detect whether or not they're on an old browser before running that line, as modern browsers will use that header to determine what program the file should be opened with.

php header() function problem about download file

I have a file download function in my website. it works fine before. but after we moved the site to another server with runs PHP 5 (it runs on PHP 4 before). when click to download, it automatically adds a extra blank line at the beginning and the end of the file which we don't want to. Here is the code for downloading function:
header("Content-Type: application/gas");
header("Cache-control: private");
header("Content-Disposition: attachment; filename=aaa.gas");
Could anyone please help me out? Thanks!
There may be an extra blank line after the ?> that closes the PHP within the script. Exit the script after sending the file in order to prevent this from mattering.

Google Chrome renames file .xml to .download

i have this very simple download page to get an xml file.
the script works ok in firefox/IE. but chrome renames the extension of the file to ".download".
and this happens only to .xml, when you use another extension like .txt it does it without problems.
the body of the html is this:
<body>
descarga
</body>
and the php is this:
header('Content-type: "text/xml"; charset="utf8"');
header('Content-disposition: attachment; filename="example.xml"');
echo "that's it";
its very strange. any solution for this??
This is not a definite answer, just some information for you.
From the bug report:
The downloaded file may get a different name if it is considered potentially dangerous
for your computer (e.g. exe). You should then get an UI prompt in the download shelf
asking you to confirm the download (with the file still downloading in the background).
try removing 'echo "that's it";'
it makes the xml invalid and might confuse the browser.
if it doesn't help, check the actual http headers of both request and response.

Categories