我有以下代码,我使用它来强制下载文件而不是在浏览器中打开。动态设置内容类型
if(isset($_POST['file_name'])){
$player_file = $_POST['file_name'];
$accessKey = "REMOVED";
$secretKey = "REMOVED";
$bucket = $_POST['bucket'];
$fname = $_POST['fname'];
$zip_url = el_s3_getTemporaryZipLink($accessKey, $secretKey, $bucket, $fname);
$mp3_url = el_s3_getTemporaryMP3Link($accessKey, $secretKey, $bucket, $fname);
header('Content-type: audio/mpeg3');
header('Content-Disposition: attachment; filename="themixtapesite_'.$player_file.'"');
readfile($mp3_url);
exit();
}
正如你所看到的,我通过了一个窗体中的所有变量。然后使用该信息为存储在Amazon S3上的文件生成唯一的Signed URL。
如果文件是MP3,我需要它使用$ mp3_url,如果它是一个Zip文件,我需要使用$ zip_url。
这一定很简单,但我一直坐在这个屏幕前面整天现在我已经有了一个完整的头脑空白!
任何帮助表示赞赏。
创建一个数组控件扩展。检查请求文件的扩展名并据此设置内容类型。 – SachinGutte
依靠扩展内容类型检查是一个坏习惯... – BenM