gpt4 book ai didi

php - 用于移动设备的 HTTP header "Content-Type: application/force-download"的实用程序?

转载 作者:IT王子 更新时间:2023-10-29 00:57:24 25 4
gpt4 key购买 nike

我目前正在开发一个 PHP 脚本,它允许您通过访问链接从您的移动设备下载媒体内容(视频、音频、图片...)。 (即 http://www.my-web-site.com/download.php?id=7ejs8ap )当我用最近的手机(三星 Galaxy S、iPhone 4S、其他一些......)测试它时,我的脚本工作得非常好,但我的旧手机三星 C3050 出现错误。我想下载的媒体只是一个音频 mp3 文件,我通常很容易下载。

错误似乎是“未知内容类型”。因此,由于我唯一的 HTTP header Content-Type 是“application/force-download”,我尝试对此发表评论并重试。然后,它起作用了。但是现在,我目前正在询问这个 Content-Type 是什么意思,以及它是否对其他移动设备是强制性的。我在没有 Content-Type 的情况下在 iPhone 4 上进行了测试,它可以正常工作,但我不确定这种兼容性是否适用于所有移动设备。

有人可以向我解释 Content-Type 是如何工作的,为什么这不是标准的 MIME 或其他任何可以帮助我确定这是每次下载的可选 Content-Type 的东西,无论文件、浏览器或我正在下载的设备?

谢谢大家

这是我发送的 PHP header :

<?php
//Assume that $filename and $filePath are correclty set.
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="'.$filename.'"');
// header('Content-Type: application/force-download'); Non-standard MIME-Type, incompatible with Samsung C3050 for example. Let it commented
readfile($filePath);
?>

编辑:我刚刚尝试使用 Sony Xperia,但下载不成功:我只看到我要下载的文件的“html 编码”字节。如果 application/octet-stream 或 application/force-download 不起作用,我怎么知道我必须使用什么内容类型?

最佳答案

Content-Type: application/force-download 意思是“我,网络服务器,将对你(浏览器)说谎这个文件是什么,这样你就不会把它当作一个 PDF/Word 文档/MP3/等等,并提示用户将神秘文件保存到磁盘上”。这是一个肮脏的 hack,当客户端不执行“保存到磁盘”时会严重崩溃。

无论您使用什么媒体,请使用正确的 mime 类型(例如,audio/mpeg 用于 mp3)。

使用 Content-Disposition: 附件; etc etc header ,如果你想鼓励客户端下载它而不是遵循默认行为。

关于php - 用于移动设备的 HTTP header "Content-Type: application/force-download"的实用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10615797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com