PHP | Download the zip file in php -


i want download zip file in php. here code below.

<?php  ob_start(); // set example variables $filename = "test.zip"; $filepath = "/home/somewhere/file/zip"; // http headers zip downloads header("pragma: no-cache"); header("expires: on, 01 jan 1970 00:00:00 gmt"); header("cache-control: no-store, no-cache, must-revalidate"); header("cache-control: post-check=0, pre-check=0", false); header("content-description: file transfer"); header("content-type: application/zip"); header("content-disposition: attachment; filename=\"".$filename."\""); header("content-transfer-encoding: binary"); header("content-length: ".filesize($filepath.$filename)); readfile($filepath.$filename); ?> 

and have link in html code.

<html>     <head>     </head>     <body>         <a href="myphpfile.php">download</a>     </body> </html> 

the file downloaded when clicked link named 'donwload' can't unzip , open file.

the file name test.zip when downloaded first time , file name. extension created when click unzip. extension of file ". cpgz" not ".zip".

here log when downloaded it.

resource interpreted document transferred mime type application/zip:"myphpfile.php" 

did wrong in code? or miss something? how can fix this? uploaded file zipped in server , want download it.

the problem filepath, there's missing trailing "/" after "/home/somewhere/file/zip" working directory should be: $filepath = "/home/somewhere/file/zip/";


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -