i created with php zip ( http://php.net/manual/de/book.zip.php ) a zip file
now i have to send it to the browser / force a download for it.
i created with php zip ( http://php.net/manual/de/book.zip.php ) a zip file
now i have to send it to the browser / force a download for it.
If you already have your ZIP on the server, and if this ZIP is reachable by Apache in HTTP or HTTPS, then, you should redirect to this file instead of "reading it" with PHP.
It's much more efficient as you don't use PHP, so no CPU or RAM are needed, and it will be faster to download, as no reading/writing by PHP needed too, only direct download. Let's Apache do the job!
So a nice function could be:
I hope that it will help.
Set the content-type, content-length and content-disposition headers, then output the file.
Setting
Content-Disposition: attachment
will suggest the browser to download the file instead of displaying it directly.You need to do it this way, otherwise your zip will be corrupted:
So content-length header needs a real string, and filesize returns and integer.