PHP发送应用程序/ zip MIME但Chrome认为它是文档

I'm using PHP to download a file like this:

index.php

<?php

// no code above, file starts and ends exactly like this sample
$u = filter_input(INPUT_SERVER,'REQUEST_URI',FILTER_SANITIZE_STRING);

// Just to test Chrome with and without .zip at the end of URL to see
// if Chrome act any different
if ($u!='/download/xsi1nc3su' && $u!='/download/xsi1nc3su.zip'){

   echo 'Wrong URL';
   die();

}else{

   $file = __DIR__.'/1.zip';

   // I've checked both of these lines and result is the same:
   // header('Content-type: '.mime_content_type($file));
   // header('Content-type: application/zip'); 

   header('Content-Description: File Transfer');
   header('Content-type: application/zip');
   header('Content-Disposition: attachment; filename=download.zip');
   header('Content-Transfer-Encoding: binary');
   header('Connection: Keep-Alive');
   header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60)));
   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
   header('Pragma: public');
   header('Content-Length: '.filesize($file));

   flush();
   readfile($file);
   exit;
}

.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</IfModule>

As you can see all URLs coming to index.php and when I use URL like (Paste directly to the browser):

http://127.0.0.1/download/xsi1nc3su.zip

or

http://127.0.0.1/download/xsi1nc3su

Chrome console shows me this warning:

Resource interpreted as Document but transferred with MIME type application/zip

I've read about this warning in this and this posts. They want to solve the problem by adding empty download in a tag (Which can only solve the problem when using download URL inside HTML link) or adding correct type to the header.

Since I'm sending correct MIME and just copy and paste the URL. I don't know where is the problem.

Please let me know, if you cannot reproduce it. I can provide my sample .zip file. My zip file contains a simple text file, created by Archive Manager on Ubuntu.

More Information

  • Chrome: Version 75.0.3770.100 (Official Build) (64-bit) Linux

  • Apache: Server version: Apache/2.4.29 (Ubuntu)

  • PHP: PHP 7.2.19-0ubuntu0.18.04.1

Chrome Console

Chrome Network

Chrome Headers

I've noticed even direct file giving me the same warning:

Chrome Console

Chrome Headers

Checked with Hexadecimal Editor. seems original and downloaded files are the same:

Original File:

50 4B 03 04 14 00 08 00 08 00 3A 2F E6 4E 00 00 00 00 00 00 00 00 AD 03 00 00 09 00 20 00 69 6E 64 65 78 2E 70 68 70 55 54 0D 00 07 D1 9A 20 5D D6 9A 20 5D D1 9A 20 5D 75 78 0B 00 01 04 00 00 00 00 04 00 00 00 00 8D 52 51 6F D3 30 10 7E CF AF 38 A4 4A 4E A0 6D 36 21 ED 21 A5 42 13 CD 46 44 57 8D 34 05 81 2A 45 6E 72 6D AC 25 B6 65 3B 5D 3B C4 7F C7 4E D6 07 0A 43 3C F8 E1 EE BE FB EE FB CE F7 EE BD AC A4 E7 85 21 70 01 85 28 11 E8 46 EC 71 08 5B 56 23 68 43 95 D1 40 79 09 C8 4B 0D 78 A0 85 A9 8F 50 B3 07 04 53 31 0D 9A 36 B2 46 6F D0 C2 D4 B5 18 54 39 E3 B2 35 7E B2 B8 5F 65 F9 32 4E BF C4 E9 90 A4 F1 E7 55 BC CC F2 55 9A 90 E1 4D 32 CF E2 34 5F 5E 2F 92 2C F9 1E E7 CB 2C 4D 16 B7 C1 C4 C3 A2 12 30 68 27 1E DB 82 3F 68 5F 4D 49 58 8A 47 5E 0B 5A 86 07 CD 2E 79 F1 56 B7 24 F8 E1 01 40 87 25 5F 95 E0 3B 58 A5 73 32 71 C9 92 A1 6F 79 7E 62 AD B1 43 0D 3A 1B 53 C8 F3 59 92 E6 F9 98 84 97 E3 27 26 2D DA 55 AD EB 84 EC 11 8A 0A 8B 07 2C 61 23 4C 05 62 6B 9D A1 46 6B 92 63 EF DD C6 A0 50 B7 B5 01 6B D9 45 D6 36 46 CF 14 15 D2 12 95 4F 3E 08 6E 90 9B 91 39 4A 8C 80 8C 1B D6 60 5E F4 C9 DC 25 FD 4E 4D 10 4C FE D9 48 A5 AC 59 41 0D 13 3C 74 52 83 09 74 62 CF D1 33 D4 85 62 D2 E1 22 B8 71 36 33 45 B9 DE A2 22 FD 84 FF A5 FF 2B 39 D3 52 68 D6 93 53 63 68 51 35 36 3F E9 CE 82 5B F3 D3 D3 C7 8C 5F 26 39 E9 19 C5 DC 5E 16 E3 BB 08 36 8C 53 75 FC 13 CF B1 E8 67 7D 42 94 A3 EB 9A ED F1 0C 14 1F 24 B3 7F E0 16 BB 6B 4A 6A D0 27 B3 21 94 70 07 DF E0 63 C4 22 0D EB DB F5 DD 3A 23 43 30 76 F1 7E 00 6F C0 BF BA 80 D7 70 75 11 04 67 03 AD 1D 1C 39 99 4A D4 11 34 AD 36 23 85 7B 5A 33 47 3C 04 6B DD 8C BA A3 98 5E D8 48 E1 29 38 D3 74 AF E8 AE A1 11 C8 76 63 77 FA C2 16 E6 C8 77 A6 72 BA DD EE 34 7B FA FD 0E DC DB D6 AD AE FC 3E 56 B6 DD 95 9F 41 5D 0E 0F CC D8 AB F6 7E 01 50 4B 07 08 F4 36 42 1F 0A 02 00 00 AD 03 00 00 50 4B 01 02 14 03 14 00 08 00 08 00 3A 2F E6 4E F4 36 42 1F 0A 02 00 00 AD 03 00 00 09 00 20 00 00 00 00 00 00 00 00 00 FF 81 00 00 00 00 69 6E 64 65 78 2E 70 68 70 55 54 0D 00 07 D1 9A 20 5D D6 9A 20 5D D1 9A 20 5D 75 78 0B 00 01 04 00 00 00 00 04 00 00 00 00 50 4B 05 06 00 00 00 00 01 00 01 00 57 00 00 00 61 02 00 00 00 00

Downloaded File:

50 4B 03 04 14 00 08 00 08 00 3A 2F E6 4E 00 00 00 00 00 00 00 00 AD 03 00 00 09 00 20 00 69 6E 64 65 78 2E 70 68 70 55 54 0D 00 07 D1 9A 20 5D D6 9A 20 5D D1 9A 20 5D 75 78 0B 00 01 04 00 00 00 00 04 00 00 00 00 8D 52 51 6F D3 30 10 7E CF AF 38 A4 4A 4E A0 6D 36 21 ED 21 A5 42 13 CD 46 44 57 8D 34 05 81 2A 45 6E 72 6D AC 25 B6 65 3B 5D 3B C4 7F C7 4E D6 07 0A 43 3C F8 E1 EE BE FB EE FB CE F7 EE BD AC A4 E7 85 21 70 01 85 28 11 E8 46 EC 71 08 5B 56 23 68 43 95 D1 40 79 09 C8 4B 0D 78 A0 85 A9 8F 50 B3 07 04 53 31 0D 9A 36 B2 46 6F D0 C2 D4 B5 18 54 39 E3 B2 35 7E B2 B8 5F 65 F9 32 4E BF C4 E9 90 A4 F1 E7 55 BC CC F2 55 9A 90 E1 4D 32 CF E2 34 5F 5E 2F 92 2C F9 1E E7 CB 2C 4D 16 B7 C1 C4 C3 A2 12 30 68 27 1E DB 82 3F 68 5F 4D 49 58 8A 47 5E 0B 5A 86 07 CD 2E 79 F1 56 B7 24 F8 E1 01 40 87 25 5F 95 E0 3B 58 A5 73 32 71 C9 92 A1 6F 79 7E 62 AD B1 43 0D 3A 1B 53 C8 F3 59 92 E6 F9 98 84 97 E3 27 26 2D DA 55 AD EB 84 EC 11 8A 0A 8B 07 2C 61 23 4C 05 62 6B 9D A1 46 6B 92 63 EF DD C6 A0 50 B7 B5 01 6B D9 45 D6 36 46 CF 14 15 D2 12 95 4F 3E 08 6E 90 9B 91 39 4A 8C 80 8C 1B D6 60 5E F4 C9 DC 25 FD 4E 4D 10 4C FE D9 48 A5 AC 59 41 0D 13 3C 74 52 83 09 74 62 CF D1 33 D4 85 62 D2 E1 22 B8 71 36 33 45 B9 DE A2 22 FD 84 FF A5 FF 2B 39 D3 52 68 D6 93 53 63 68 51 35 36 3F E9 CE 82 5B F3 D3 D3 C7 8C 5F 26 39 E9 19 C5 DC 5E 16 E3 BB 08 36 8C 53 75 FC 13 CF B1 E8 67 7D 42 94 A3 EB 9A ED F1 0C 14 1F 24 B3 7F E0 16 BB 6B 4A 6A D0 27 B3 21 94 70 07 DF E0 63 C4 22 0D EB DB F5 DD 3A 23 43 30 76 F1 7E 00 6F C0 BF BA 80 D7 70 75 11 04 67 03 AD 1D 1C 39 99 4A D4 11 34 AD 36 23 85 7B 5A 33 47 3C 04 6B DD 8C BA A3 98 5E D8 48 E1 29 38 D3 74 AF E8 AE A1 11 C8 76 63 77 FA C2 16 E6 C8 77 A6 72 BA DD EE 34 7B FA FD 0E DC DB D6 AD AE FC 3E 56 B6 DD 95 9F 41 5D 0E 0F CC D8 AB F6 7E 01 50 4B 07 08 F4 36 42 1F 0A 02 00 00 AD 03 00 00 50 4B 01 02 14 03 14 00 08 00 08 00 3A 2F E6 4E F4 36 42 1F 0A 02 00 00 AD 03 00 00 09 00 20 00 00 00 00 00 00 00 00 00 FF 81 00 00 00 00 69 6E 64 65 78 2E 70 68 70 55 54 0D 00 07 D1 9A 20 5D D6 9A 20 5D D1 9A 20 5D 75 78 0B 00 01 04 00 00 00 00 04 00 00 00 00 50 4B 05 06 00 00 00 00 01 00 01 00 57 00 00 00 61 02 00 00 00 00
douyun1860
douyun1860 我注意到Chrome甚至给了我直接文件的警告(有和没有.htaccess)。在问题中添加了十六进制编辑器结果。它们看起来完全一样。
一年多之前 回复
doubaben7394
doubaben7394 Chrome是否有可能过于聪明,并且检测到响应不是有效的ZIP?你有没有用例如验证下载十六进制编辑器?
一年多之前 回复
dtdr57046
dtdr57046 当我将URL直接粘贴到地址栏或单击HTML链接时,我收到相同的警告。
一年多之前 回复
douyingtai6662
douyingtai6662 当您将URL复制并粘贴到浏览器地址栏时,或者您是否尝试以其他方式触发此请求时,您会得到此信息?
一年多之前 回复
dtnd30892
dtnd30892 单击网络面板中的请求,然后检查响应标头。
一年多之前 回复
dongqian8265
dongqian8265 检查浏览器开发工具的网络面板中的响应头,这些是什么样的?
一年多之前 回复
drkjzk3359
drkjzk3359 不,Chrome给了我同样的警告。
一年多之前 回复
doqdcks3948
doqdcks3948 如果你添加.htaccess文件AddTypeapplication/zip.zip有什么变化吗?
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐