phpEnthusiast
phpEnthusiast

Reputation: 45

Download .zip file problem (downloading .php file)

I want to download a .zip file, but when i go to download it, it forces me to download the .php file. I use this simple code that is all over the internet so I don't know why I can't download .zip file.

header("Cache-Control: no-store, no-cache, must-revalidate");  
header("Cache-Control: post-check=0, pre-check=0", false);  
header("Pragma: no-cache");  
header("Content-type: application/zip");  
header('Content-length: '.filesize($fullpath));  
header("Content-disposition: attachment; filename=".basename($fullpath));  

readfile($fullpath);  

Upvotes: 0

Views: 4676

Answers (2)

SAIF
SAIF

Reputation: 189

I think you are downloading the zip file named as .php
try to open the downloaded file with winzip or winrar

Upvotes: 0

Pekka
Pekka

Reputation: 449783

If you are serving the PHP file with a .zip extension, getting the PHP source code for download is expected behaviour - ZIP files do not get parsed by the PHP interpreter by default.

You would have to register the ZIP extension to be parsed by PHP. That is pretty sub-optimal, though; in this case, you can link to the PHP file with the .php extension. The filename header will provide the correct name to the user who downloads the file.

If you are using a .php extension and the source code of your PHP file is served, your server configuration is broken.

Upvotes: 1

Related Questions