简体   繁体   English

在我的服务器中,MIME类型“ application / octet-stream”已切换为“ text / html”。 怎么预防?

[英]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.

相关问题 如何处理图像的mime类型“application / octet-stream”? - how handling image's mime type “application/octet-stream”? 获取上载图像的MIME类型是application / octet-stream - Getting Upload Image mime type is application/octet-stream 应用程序/八比特流MIME类型是否可以安全上传? - Is the application/octet-stream MIME type safe for uploading? Codeigniter的应用程序/八位字节流MIME类型问题 - application/octet-stream mime type issue with codeigniter 服务器上的PHP文件上传将mime-type更改为application / octet-stream - PHP file upload on server changed mime-type to application/octet-stream 干预图像 - 如何上传 MIME 类型的图像:application/octet-stream - Intervention Image - how to upload images with MIME type: application/octet-stream 如何处理应用程序/八位字节流类型的API响应 - How to deal with application/octet-stream type API response 为什么 mime_content_type 上的某些 mp3 返回应用程序/八位字节流 - why some mp3s on mime_content_type return application/octet-stream 尝试在docx文件上获取mime类型会导致应用程序/字节流 - Trying to get mime type on docx files results in application/octet-stream PHP生成的JSON文件具有application / octet-stream mime类型 - JSON file generated by PHP has application/octet-stream mime type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM