exporting csv to iOS 9 safari .. unable to read document - php

I'm using php to export a csv to mobile safari. I'm getting this error when I try to download the csv.
Does anyone have any ideas?
ini_set('memory_limit', '2048M');
header("Cache-Control: must-revalidate");
header("Pragma: must-revalidate");
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=Activity.csv");
header("Expires: 0");

i changed content-type to this.. solved it
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

Related

PHP - excel file download

I download files from server but excel or word files are corrupted after download. Pdfs, jpgs etc. are ok.
ob_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: ").$att->getType();
header("Content-Disposition: attachment; filename=" . basename($att->getName()));
header("Content-Transfer-Encoding: binary");
header("Content-Description: File Transfer");
readfile($path);
Content type for excel I have - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Just Change
header("Content-Type: ").$att->getType();
to
header("Content-Type: ".$att->getType());
You send file with null Content-Type...
For excel and word, try changing
header("Content-Type: ").$att->getType();
to
header("Content-Type: application/octet-stream");
or, for excel
header("Content-Type: application/vnd.ms-excel");
or, for word
header("Content-Type: application/msword");
Problem was different... I've just had in my php file new line after ?>
Thank Amin and Ken for help

Firefox downloads retrieve.php instead of filename given per Content-Disposition header

I have a PHP script called retrieve.php that compresses uploaded files from a directory in to a .zip file and then outputs them to the stream, so said file can be downloaded.
The script works in all browsers except Firefox.
After searching online for quite a while now and coming across this question: PHP download script returns download-file.php instead of filename and still having the same issue, I'm stumped and have no clue what's going wrong.
This is the code being used to download the file:
if ($zippedElements >= 1) {
// die($zipFilename);
$zipFilename = "download-".time().".zip";
// Send zip to recipient
header("Content-Dispositon: attachment; filename=\"$zipFilename\"");
header("Content-Length: ".filesize($zipFileName));
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
header("Connection: Keep-Alive");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Accept-Ranges: bytes");
readfile($zipFileName);
} else return;
I've tried setting the header to different values, such as content-type: application/force-download, adding the asterisk (*) after filename, etc., but all to no avail.
The result in Firefox looks as follows:
Any help with the matter would be much appreciated.
You have inconsistencies in the variable name $zipFilename - the N is uppercased sometimes.
$zipFilename = __FILE__;
// Send zip to recipient
header("Content-Dispositon: attachment; filename=\"$zipFilename\"");
header("Content-Length: ".filesize($zipFilename));
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
header("Connection: Keep-Alive");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Accept-Ranges: bytes");
readfile($zipFilename);

Facing issue of downloading script in PHP

I am facing a problem of downloading script, whenever download on my project site starts, all links present in the site does not work at all.
Once file gets downloaded completely, link starts working.
I am setting header and using readfile method of php for download the file. I want that file downloading should work simultaneously with users actions on the site.
I am using following code
header("Pragma: public");
header("Expires: 0");
header("Content-Type: application/$ctype");
header("Content-Description: File Transfer");
header("Content-Disposition: inline; filename=$docName");
header('Content-Length: '. filesize($filename));
header("Accept Ranges: bytes");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
readfile("$filename");
Here filename is name of file and ctype is file type.
How to resolve this?
Please let me know if anybody have solution for this.
I'm just guessing that you're missing a proper header, change content type and transfer encoding as you need
$download is the actual file i.e. /var/www/download_images/1.jpg
$filesize is the size of the file
$filename can be any filename that you want presented to the user i.e. homer_simpson.jpg
<?php
if (file_exists($download))
{
header("Cache-Control: must-revalidate");
header("Expires: 0");
header("Pragma: public");
header("Content-Description: File Transfer");
header("Content-Length: ". $filesize .";");
header("Content-Disposition: attachment; filename=" . $filename);
header("Content-Type: application/octet-stream; ");
header("Content-Transfer-Encoding: binary");
ob_clean();
flush();
readfile($download);
}
?>

Force PRS-T1 browser to download file with .htaccess-authentification

I have a php-download script that looks like this:
<?php
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-Type: $mimeType");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $size");
// Read the file from disk
readfile($path);
?>
Normally with this I can force my E-Book-Reader (a Sony PRS-T1) to download a file. However, if I use the same script inside of a folder with .htaccess-authentication, the download fails.
On my computer, the download works, no matter if there is a .htaccess-authentication or not.
Can you help me to find the reason for this behaviour of my Ebook-Reader and make downloads inside of protected folders possible?
Thank you!
[edit]
The PRS-T1 runs Android. Maybe this issue (link) is the answer - it is simply not possible...?

Download file from site PHP

I would to know the command in a PHP script to get in output and save a file from my site.
Thanks
See here for a good description of how to force the output of a php script to be a download.
The basics of it are:
// Set headers
header("Cache-Control: public");
header("Content-Description: File Download");
header("Content-Disposition: attachment; filename=" + $filename);
header("Content-Type: application/zip"); // or whatever the mime-type is
// for the file you want to download
header("Content-Transfer-Encoding: binary");
// Read the file from disk
readfile($full_path_to_file);
As an addition (provided by Gordon's comment), see the 1st example on the php documentation here
At the End of the files or used in clicking files, you can add this
$filesh = "check.xls";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($filesh));
header("Content-Description: File Transfer");
readfile($filesh);
if you got any header using problem means, top of the file you can add ob_start(); function
If you mean getting output, contents from other site or location, this what you need file_get_contents

Categories