Tuesday, November 19, 2013

how to create zip file to multiple pdf, image, and other documents using php

Step-1> simple create a zipcreation.php and paste below those code and run some change are destination url and your multiple file location have to change
//Author : Bikash ranjan nayak
/* creates a compressed zip file */
function Create_YourFilestoZip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
//if we have good files...
if(count($valid_files)) {
//class ZipArchive is php built libary class
$zipobj = new ZipArchive();
if($zipobj->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
//add the files
foreach($valid_files as $file) {
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;

//close the zip -- done!

//check to make sure the file exists
return file_exists($destination);
return false;

$list_of_files_for_zip = array(

//if true, good; if false, zip creation failed
    echo "zip file has been created success fully";
    echo "zip file creation fail";

No comments:

Post a Comment