【问题标题】:MIME Type 'application/octet-stream' is switched to 'text/html' in my server. How to prevent?MIME 类型“application/octet-stream”在我的服务器中切换为“text/html”。如何预防?
【发布时间】:2015-08-29 05:48:54
【问题描述】:

我正在尝试从服务器下载我的 .mp3 文件,但是当我传递以下代码时,它会在浏览器屏幕上以二进制转换方式打印文件 Content-Type: text/html;charset=UTF-8.

如果我在其他服务器上尝试相同的代码,它会以 Content-Type: application/octet-stream 成功运行。所以我可以说代码 100% 有效(代码在 PHP 中)。

那么这是服务器配置问题还是其他问题?请帮我解决这个问题。

<?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;
?>

【问题讨论】:

  • 你是直接下载.mp3还是通过.php脚本下载?
  • 启用error_reporting(E_ALL)
  • 是的,我正在使用 PHP 代码

标签: php ubuntu server amazon


【解决方案1】:

是的,它可能是服务器配置。首先,尝试将您的原始 mp3 上传到服务器并像http://yourserver.com/file.mp3 一样访问它。 如果可以,那么你的 php 有问题,如果你不能 - 调整服务器。

【讨论】:

  • 是的,根据您的指导,我也这样做了。但我无法正确地做。
  • 是的,我的 php 代码是正确的,因为我可以在其他服务器上成功运行它。
  • 所以调整服务器或使用另一个服务器,也许它仅限于服务器 mp3,这是很常见的做法
  • 是的,但这不是切换服务器的解决方案。我必须使用那台服务器。
  • 您拥有什么级别的访问权限?可以更改配置文件吗?那是什么样的服务器?阿帕奇,nginx?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-19
  • 2012-03-31
  • 2015-02-17
  • 2015-05-30
  • 2012-04-16
相关资源
最近更新 更多