【问题标题】:file download Resource interpreted as Document but transferred with MIME type application/octet-stream文件下载 资源解释为文档,但使用 MIME 类型 application/octet-stream 传输
【发布时间】:2016-11-23 00:40:58
【问题描述】:

我在用于文件下载的页面中有一个 iframe。我使用 mp3 歌曲路径和磁贴将 iframe 源设置为指向此 php 文件。

<?php 
    header("Content-Type: application/octet-stream");
    $name = $_GET['name'];
    header("Content-Disposition: attachment; filename=\"$name\"");
    $path = str_replace(' ', '%20', $_GET['path']);
    readfile($path);
    exit;
?>

当我尝试从本网站的音频播放器下载 mp3 歌曲时:

http://janeingalls.com/

我在控制台中收到此消息,下载时文件大小始终为 0 字节。

Resource interpreted as Document but transferred with MIME type application/octet-stream

【问题讨论】:

    标签: php download mime


    【解决方案1】:

    添加一个标题告诉浏览器知道文件的路径后文件有多大:

    ...
    header('Content-Length: ' . filesize($path));
    readfile($path);
    exit;
    

    【讨论】:

      猜你喜欢
      • 2013-08-08
      • 2013-08-25
      • 2012-04-26
      • 2017-01-30
      • 1970-01-01
      • 2023-03-27
      • 2014-11-19
      • 2012-12-08
      • 2011-04-23
      相关资源
      最近更新 更多