简体   繁体   中英

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);  

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM