Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Download file script not working on iPad

I have a file download script that I have written, which reads files from below public_html and allows the user to download them after checking to see if the user is logged in and that the file is a valid file for them to download.

An issue I've recently come across is that on an iPad it just fails to do anything when the link is clicked.

Example download file code after all the checks have been done:

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: application/msword");
header("Content-Disposition: attachment; filename=\"file.doc\";" );
header("Content-Length: 50688");

readfile(SITE_PATH .'/files/file.doc');

This script has been tested and checked on PC, Mac and Linux machines in multiple browsers (FF, Opera, IE6-9, Chrome, Safari) and all seem to work fine, so it must be something that the iPad does differently.

I'd imagine it's something to do with the iPad not actually having a file structure as such to download files to, but I'm not certain.

Has anyone come across this problem before? If so, is there a fix?

like image 969
Nick Avatar asked Jan 13 '12 10:01

Nick


1 Answers

iOS Safari does not support file download..

Update: But if you are looking to open the .doc files on iPad then yes.. you can do that...

use following -

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: application/msword");


readfile('file.doc');

the only difference in your code and mine is I removed the header for attachment Just remove these header -

header("Content-Disposition: attachment; filename=\"file.doc\";" );
header("Content-Length: 50688");

Actually you can check for client operating system if operating system is iOS then don't add header for download like this -

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: application/msword");

if (!Operating_System_Is_IOS)
{

     header("Content-Disposition: attachment; filename=\"file.doc\";" );
     header("Content-Length: 50688");

}

readfile(SITE_PATH .'/files/file.doc');
like image 58
Saurabh Avatar answered Oct 20 '22 18:10

Saurabh