[英]MIME Type 'application/octet-stream' is switched to 'text/html' in my server. How to prevent?
I am trying to download my .mp3 file from server but when I pass below code , it prints the file at browser screen in binary converting Content-Type: text/html;charset=UTF-8 . 我正在尝试从服务器下载.mp3文件,但是当我通过以下代码时,它将在浏览器屏幕上以二进制格式将文件打印成Content-Type:text / html; charset = UTF-8 。
If I tried same code to other server, It runs successfully with Content-Type: application/octet-stream . 如果我在其他服务器上尝试了相同的代码,则它会以Content-Type:application / octet-stream成功运行。 So I can say code is 100% valid (code is in PHP ). 所以我可以说代码是100%有效的(代码在PHP中 )。
So Is this problem in server configuration or any other issue? 那么,这是服务器配置中的问题还是其他任何问题? Please help me to resolve this problem. 请帮助我解决此问题。
<?php
set_time_limit(0);
$url = 'https://abcdefgh.s3.amazonaws.com/audio/1431428586_z3PtL.mp3';
$file = basename($url);
$fp = fopen($file, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
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');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
?>
yes, it could be the server configuration. 是的,可能是服务器配置。 firstly, try to upload your original mp3 to the server and access it like http://yourserver.com/file.mp3 . 首先,尝试将原始mp3上传到服务器,然后像http://yourserver.com/file.mp3一样对其进行访问。 If you can, then something wrong with your php, if you cannot - tweak the server. 如果可以,那么您的php出了点问题,如果不能-调整服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.