我想要写一个PHP脚本下载一些文件 - 移动浏览器(扩展名.apk文件,.dcm,.PDF,.zip文件等)。我已经写一个PHP code下载这些文件,它是在所有的浏览器(而不是移动浏览器)工作的罚款。但我想用HTC手机,并试图打开,而不是下载(如打开一个网页)的文件了。
I want to write a php script to download some files(extensions - .apk, .dcm, .pdf, .zip etc...) on mobile browsers. I have written a php code to download those files and it is working fine on all the browsers(not mobile browsers). But I tried it using a HTC mobile and it is trying to open the file instead of downloading(like opening a web page).
我怎样才能使移动浏览器的下载?
How can I enable the download on mobile browsers?
感谢您
PS:这就是我要做的事。我用一个jQuery code一些参数发送到PHP文件,它会返回相应的下载文件的路径。
PS: This is how I do it. I use a jquery code to send some parameters to a php file and it will return the appropriate download file path.
jQuery的code片段是:
jQuery code snippets is:
$.post('saveData.php',{ name: name.val(), email: email.val(), phone:phone.val(), address:address.val(), version:vers, swVersion:swvers, type:type }, function(data) { var links = data; document.body.innerHTML += "<iframe src='" + links + "' style='display:hide;' ></iframe>"; });链接变量包含PHP文件下载路径的回报。IFRAME允许下载窗口弹出。不过,这并不在移动浏览器的工作。
"links" variable contains the download path return from the php file. Iframe allow the download window to popup. But it does not work on the mobile browsers.
推荐答案尝试用下面的标题:
header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename="filename"');我们的想法是设置内容类型的东西,浏览器不知道如何打开 - 这样它会显示保存对话框。你可以用实际的MIME类型尝试,它应该工作,但现在我无法进行测试。
The idea is to set the content type to something that the browser doesn't know how to open - that way it will show the save dialogue. You can try it with the actual MIME type, it should work, but I can't test it right now.
更多推荐
如何强制文件中使用移动浏览器PHP下载?
发布评论