Opening downloaded zip file creates cpgz file?

后端 未结 6 1833
盖世英雄少女心
盖世英雄少女心 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:39

    Ok, I answered my own question.

    The main problem, which I originally didn't make clear, was that the file was not located on my application server. It was in a Amazon AWS s3 bucket. That is why I had used a full url in my question, http://mysite... and not just a file path on the server. As it turns out fopen() can open urls (all s3 bucket "objects", a.k.a. files, have urls) so that is what I did.

    Here's my final code:

    $zip= "http://mysite.com/uploads/my-archive.zip"; // my Amazon AWS s3 url
    header("Content-Type: archive/zip"); // works with "application/zip" too
    header("Content-Disposition: attachment; filename='my-archive.zip"); // what you want to call the downloaded zip file, can be different from what is in the s3 bucket   
    $zip = fopen($zip,"r"); // open the zip file
    echo fpassthru($zip); // deliver the zip file
    exit(); //non-essential
    

提交回复
热议问题