我有一个简单的脚本,允许某人将电影文件下载到他们的设备上。该代码适用于我测试过的所有内容,但 Andriod 除外。 Android 设备会删除名称和文件扩展名。它可能会调用文件 2.qt 或 .bin。为什么会失败?
<?php
if(isset($_GET['filename'])) {
header('Content-Description: File Transfer');
header('Content-Type: movie/quicktime');
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");
} else {
echo "Link: <a href='test.php?filename=test.mov'>Download Video</a>";
}
?>
最佳答案
Because Android doesn't natively support Quicktime, an Apple technology.也很可能用于下载此应用程序的客户端不尊重 http 信封上设置的文件名作为它用于将文件写入文件系统的名称,因为有 nothing forcing it to。 .
关于php - 为什么这个 PHP 下载脚本只在 Android 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8020818/