Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php强制下载扩展_Php - Fatal编程技术网

php强制下载扩展

php强制下载扩展,php,Php,我正在尝试强制下载,因此这是我的代码: $file = 'test.m4r'; $mime = 'audio/aac'; header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for cer

我正在尝试强制下载,因此这是我的代码:

$file = 'test.m4r';
$mime = 'audio/aac';
header("Pragma: public"); // required
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header('Content-Description: File Transfer');
header("Content-Type: $mime");
header('Content-Length: ' . filesize($file));          
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);
文件扩展名应该是.m4r,即使mime是aac。在某些计算机上,它作为test.m4r下载,而在其他计算机上,该文件的扩展名为test.m4r.acc。如何解决此问题


谢谢大家!

关于mimetype,你可以撒谎,但除此之外,你也无能为力。 尝试:

“应用程序/八位字节流”

这可能有效,并且是未知文件类型等的默认设置。

试试这个

<?php header("Content-Type: application/force-download"); ?>