Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: How to download zip with php without messy code

Snow:

I want to download xxx.zip in my linux server.

And I got the Code from php offical web site. The url is


http://ift.tt/1hRNNJx

I have set content-Type: application/zip. But unlucky, when executing the download.php, I got Messy Code in firfox or chrome browser.

My linux charset and browser charset are both utf-8.

Here is my download.php code:


$file_name = "xxx.zip";
if (!file_exists ($file_name)){
echo "file is not exist";
exit();
}
else{
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file_name));

readfile ($file_name);
exit;
}
?>

Compress xxx.zip code is:


$fileArr={1.jpg,2.jpg,3.jpg};

$fpName="xxx.zip";

$zip=new ZipArchive();
$zip->open($fpName,ZipArchive::CREATE);
foreach($fileArr as $file)
{
$zip->addFile("files/".$file,basename($file));
//$zip->renameName($file,$fileChName);
}
$zip->close();
?>

However, I can download xxx.zip file with xftp from linux server, and decompressing xxx.zip successfully in my windows desktop.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: How to download zip with php without messy code

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×