nic*_*noe 40 php mobile content-type http download
我目前正在开发一个PHP脚本,允许您通过访问链接从移动设备下载媒体内容(视频,音频,图片...).(即http://www.my-web-site.com/download.php?id=7ejs8ap)当我用最近的手机(三星Galaxy S,iPhone 4S,其他一些人)测试时,我的脚本非常有用. )但我的旧手机三星C3050出现错误.我想下载的媒体只是一个音频mp3文件,我通常很容易下载.
该错误似乎是"未知内容类型".因此,由于我唯一的HTTP标头Content-Type是"application/force-download",我尝试对此进行评论并再试一次.然后,它的工作原理.但是现在,我目前正在询问这种内容类型的含义以及是否可以强制其他移动设备.我在iPhone 4上没有使用Content-Type进行测试,但它确实有效,但我不确定所有移动设备的兼容性.
有人可以解释一下Content-Type是如何工作的,为什么这不是标准的MIME或其他所有可以帮助我确保这是每个下载的选项内容类型,无论文件,浏览器或设备是什么我正在下载?
感谢大家.
这是我发送的PHP标头:
<?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);
?>
Run Code Online (Sandbox Code Playgroud)
编辑:我刚试过索尼Xperia,下载不成功:我只看到我要下载的文件的"html编码"字节.如果application/octet-stream或application/force-download不起作用,我怎么知道我必须使用哪种内容类型?
Que*_*tin 115
Content-Type: application/force-download意思是"我,网络服务器,我会骗你(浏览器)关于这个文件是什么,所以你不会把它当作PDF/Word文档/ MP3 /其他什么,并提示用户将神秘文件保存到磁盘而不是".当客户端没有"保存到磁盘"时,这是一个可怕的破解.
对于您正在使用的任何媒体(例如,audio/mpeg用于mp3),请使用正确的mime类型.
Content-Disposition: attachment; etc etc如果您希望鼓励客户端下载它而不是遵循默认行为,请使用标头.
Sur*_*mar 13
要下载文件,请使用以下代码...将文件名与位置存储在$ file变量中.它支持所有mime类型
$file = "location of file to download"
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
Run Code Online (Sandbox Code Playgroud)
要了解Mime类型,请参阅此链接:http://php.net/manual/en/function.mime-content-type.php