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?


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');

Apple has locked down the iOS devices so that you can't access the file structure. As such, they have disabled file downloads.


You can force the user to paste the link (with a time limited ID in it due to log in ...) into any third party app, like GoodReader. Or just let them view the doc file in the browser.

链接地址: http://www.djcxy.com/p/46880.html

上一篇: 下载的文件已损坏,而不是

下一篇: PHP:下载文件脚本不适用于iPad