Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download zip file "Failed network error" (PHP/NGINX)

I'm getting the following error in my browser (Chrome & Firefox) when I attempt to download a zip file from my live server, https://mysite.com: Failed network error.

Confusingly, using the same code (below) from my live server on my localhost allows me to successfully download this same zip file:

$path=$data['path_new']='uploads/some-path/';
$file_name='test.zip';
$file=$path.$file_name;

header("Content-Disposition: attachment; filename=".$file_name);    
header("Content-Type: application/octet-stream");
readfile($file);

I'm using PHP and NGINX on both my localhost and live server with I believe the same configurations, but obviously something isn't right on my live site. Might someone help?

like image 784
tim peterson Avatar asked Nov 02 '22 00:11

tim peterson


1 Answers

I had exactly the same issue, zip file download with chrome not working on live server (HTTPS) but working with localhost. Similar code. Although I got rid of gzip encoding for the download page...

if (ini_get('zlib.output_compression'))
            ini_set('zlib.output_compression', 'Off');

... I still got "Content-Encoding: gzip" in response headers. I finally added that (I know it's a bit lousy):

header_remove('Content-Encoding');

And apart from a security warning concerning zip extension it's working for me. Probably late for you, hope this can help someone.

Bye

like image 106
nicolas Avatar answered Nov 09 '22 06:11

nicolas