1

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
ICE
  • 1,667
  • 2
  • 21
  • 43
  • If you add to .htaccess file `AddType application/zip .zip ` is something change? – JarekBaran Jul 07 '19 at 07:57
  • @JarekBaran No. Chrome gives me the same warning. – ICE Jul 07 '19 at 09:21
  • Check the response headers in the network panel of the browser dev tools, what do those look like? – misorude Jul 08 '19 at 09:35
  • Click on the request in the network panel, and check the response headers. – misorude Jul 08 '19 at 11:21
  • And you get this when you just copy&paste the URL to the browser address bar, or are you trying to trigger this request some other way? – misorude Jul 08 '19 at 11:34
  • @misorude I get the same warning when I paste URL directly to the address bar or by clicking on an HTML link. – ICE Jul 08 '19 at 11:36
  • Is there a chance that Chrome is just being too smart and it's detecting that the response is not a valid ZIP? Have you verified the download with e.g. an hexadecimal editor? – Álvaro González Jul 08 '19 at 11:44
  • 1
    @ÁlvaroGonzález I've noticed Chrome even gives me the warning with direct file (with and without .htaccess). Added hexadecimal editor result to the question. They look exactly the same. – ICE Jul 08 '19 at 12:20

0 Answers0