In one of my previous post, We have already seen How we can extract Zip Files using PHP. In this tutorial, we are going to create a Zip file with PHP. To perform this task, we are going to use a built-in extension in PHP known as ZipArchive classs.
//Creating a Zip File Using PHP function genZip($files = array(),$zipName){ $zip = new ZipArchive(); $zip->open($zipName.'.zip', ZipArchive::CREATE); foreach($files as $file){ $zip->addFile($file); } $zip->close(); }
//Usage of genZip function $files = array( 'file1.pdf', 'file2.pdf', 'file3.pdf', 'folder2/file4.pdf', 'folder2/file5.pdf' ); $zipName = 'myfiles'; genZip($files,$zipName);
Hello Friends! I am Ramana a part time blogger from Hyderabad.
0 comments:
Post a Comment