In some website there is need of downloading functionality of multiple files. In that case it is headache for PHP developer that how to give option for download multiple file in single click with lower bandwidth. So, the solution is here: just create zip file containing all the files and give one link for download the zip files.
createZip.inc.php is a class which creates zip file from different files stored on various directories on server and output the necessary request response headers to serve the generated ZIP archive for download.
Example Code Snippet:
include_once("createZip.inc.php");
$createZip = new createZip;
$directoryName = "DownloadImages/";
$createZip -> addDirectory($directoryName); // Adding Directory to ZIP file
$file1ToZip = “image1.jpeg”; // filename1 which is to be added in zip
$fileContents=file_get_contents($file1ToZip);
$createZipFile->addFile($fileContents, $directoryName.$file1ToZip);
$file2ToZip = “image2.jpeg”; // filename2 which is to be added in zip
$fileContents=file_get_contents($file2ToZip);
$createZipFile->addFile($fileContents, $directoryName.$fileToZip);
$outputDir = “./”;
$outputFile = $outputDir.”Images.zip”; // Zip file name
$fd = fopen ($outputFile, “wb”); // Temporary Creating file on disk
$out = fwrite ($fd, $createZip -> getZippedfile()); // Writing zip contents to temporary file
fclose ($fd);
$createZip -> forceDownload($outputFile); // stream the generated ZIP archive for download
@unlink($outputFile); // unlink temporary file
Credits goes to Author of the class: “Rochak Chauhan”
Source: http://www.phpclasses.org/browse/package/2322.html
Author:
Vidyadhar Yagnik
PHP Developer: Digicorp Information Systems Pvt. Ltd.
[email protected]
Really a good post. It helped me a lot. Keep posting.
If anyone is having memory problems, go to the phpclasses website URL linked above
Go into the forum
Look for the post named
“Memory Problem Solved”
Attila has re-written the class to add one zip at a time, so it avoids the memory problems of the original class.
Cheers!
include_once(“createZip.inc.php”)
Please tell me code of createZip.inc.zip file urgent
please tell me proper code bacause this can not be create zip file
Dear Virendra,
You can download full source code from following link which is mentioned as a Credit.
http://www.phpclasses.org/browse/package/2322.html
This code is working fine. If you face any difficulty than pls. check your server settings and file creation permission on the directory.
how to get createZip.inc.php
Hello there, You have done an excellent job. I will certainly digg it and personally suggest to my friends. I am confident they will be benefited from this site.