资源解释为文档但使用 MIME 类型传输 application/octet-stream 控制台

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

我有一个正在构建的文件管理系统,其中只允许使用 zip 文件。我不想让任何人看到文件在服务器上的存储位置,所以我使用 ajax 调用 php 文件执行以下操作:

if (!empty($find_url)) {
    foreach ($find_url as $file) {
        $dl =  urldecode($file->file_url);
    }
    $file_headers = @get_headers($dl);
    if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
        $exists = false;
    } else {

        $exists = true;
        header('Content-Type: application/zip');
        header("Content-Transfer-Encoding: Binary"); 
        header('Location: '.$dl);

    }
}

文件下载正常,但它会输出一条控制台消息指出文件位置:

Resource interpreted as Document but transferred with MIME type application/octet-stream: 
"http://www.exmple.co.uk/someplace/filename.zip".

当我们尝试通过在浏览器中输入 url 直接下载任何文件时,chrome 似乎正常。尝试为 windows 下载 Chrome、Firefox 和 GitHub,它们在 chrome.

上的行为都相同

在提供下载时 link 您可以通过在标签内添加下载属性来解决这个问题。

<a href="http://www.exmple.co.uk/someplace/filename.zip" download>Download File</a>