PHP:下载不在iPad上运行的文件脚本 [英] PHP: Download file script not working on iPad

查看:149
本文介绍了PHP:下载不在iPad上运行的文件脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我编写的文件下载脚本,它从public_html下面读取文件,并允许用户在检查用户是否已登录后下载它们,并且该文件是一个有效的文件供他们下载。

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.

我最近遇到的一个问题是,在点击链接时,它在iPad上无法执行任何操作。

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

此脚本已在多个浏览器的PC,Mac和Linux计算机上进行测试和检查(FF,Opera ,IE6-9,Chrome,Safari)似乎工作得很好,所以它必须是iPad不同的东西。

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.

我想它是可以做的事情iPad实际上没有文件结构来下载文件,但我不确定。

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不支持文件下载..

iOS Safari does not support file download..

更新:但如果您打算在iPad上打开.doc文件,那么是..您可以这样做...

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

使用以下 -

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

实际上如果操作系统是iOS,你可以检查客户端操作系统然后不添加下载头像这样 -

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

这篇关于PHP:下载不在iPad上运行的文件脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆