Is this the correct way to download a zip file from a URL?

I found the following code that I use for downloading a zip file from a URL:

file_put_contents('tmp.zip', file_get_contents('http://mywebsite.com/myzipfile.zip'));

It worked when I tested it but I wanted to ask if this is the correct way to do this or not?

Thanks for any ideas.

I haven’t used get or put contents before, I’ve used cURL (which I’ve moved away from) and ftp_get(). I can only recommend to stay away from cURL as it can be finicky on certain files.

I’m a bit confused: what do you mean by “download?” Do you mean from server to desktop?

I don’t know if this is the “correct” way to do it but it works for me:

// push to download the zip
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$downloadname.'"');
readfile($zipname);

I mean from server to server. I use a similar script to yours for downloading from server to desktop.

Server to server your code looks fine to me. :wink: