Opening downloaded zip file creates cpgz file?

后端 未结 6 1837
盖世英雄少女心
盖世英雄少女心 2020-12-10 06:25

If I make the url for a zip file the href of a link and click the link, my zip file gets downloaded and opening it gets the contents as I expect.

Here\'

6条回答
  •  死守一世寂寞
    2020-12-10 06:44

    You're passing the URL to readfile() like:

    $archive = 'https://mysite.com/uploads/my-archive.zip';
    

    While you should pass the path on the server, for example:

    $archive = '/uploads/my-archive.zip';
    

    Assuming the file is located in the upload folder.

    Additionally try the following headers:

    header("Content-type: application/octet-stream"); 
    header("Content-disposition: attachment; filename=file.zip");  
    

提交回复
热议问题