Yii Zip Tutorials

Yii Zip Format

In this article, I explained about “How to handle zip files” in yii framework. I used this code to my project for handling the zip files. Here i added source code to create, Extract, Download and Delete zip files in yii framework.Create Zip Files in YiiExtract Zip Files in YiiDownload Zip Files in YiiDelete Zip Files in YiiCreate Zip Files in Yii <?php public function actionCreateZip(){ $zip=new ZipArchive(); $destination=DIRDetails."/filename.zip"; if($zip->open($destination,ZIPARCHIVE::CREATE) […]... Read More »

Delete zip file in yii

Delete Zip Files Using PHPHere i added this code to delete the zip files inside the folder of yii framework.SourceCode: public function actionDeletefile($id,$docid) { $error=''; $filepath=Yii::app()->basePath.'/files/'.$zipfilename.".zip"; $zip = new ZipArchive; if ($zip->open($filepath) === TRUE) { $zip->deleteName($filename); // this file of inside zip folder } else{ $error='failed'; } $zip->close(); }... Read More »

Yii 1.0 Download Zip files

Download Zip Files Using YiiHere I have added the code to download the Zip files in yii folder.SourceCode: public function downloadfinal($docid,$docname) { $filename=Dirdetails"filename.zip"; if(file_exists($filename)){ $path_parts = pathinfo($filename); $ext = strtolower($path_parts["extension"]); switch ($ext) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpg": $ctype="image/jpg"; break; default: […]... Read More »

Yii 1.0 Create Zip file

Create Zip Files Using PHPI added the source code to create a zip file in yii. public function actionCreatefile($filename,$filelist) { $zip=new ZipArchive(); $destination=DIRDetails."/filename.zip"; if($zip->open($destination,ZIPARCHIVE::CREATE) !== true) { return false; } foreach($filelist as $thefile) { $random=rand(11111,99999); $filename=$random.$thefile; $zip->addFile($thefile->tempname,$filename); } $zip->close(); }... Read More »

Yii 1.0 Extract Zip files

Extract Zip Files Using YiiI have added the source code to extract the zip files using yii public function actionExtractfile($filename) { $filename='filename'; $zipfile=DirDetails."/filename.zip"; $zip = zip_open($zipfile); $extract=DirDetails."/newfolder"; if($zip) { if(!is_dir($extract)) mkdir($extract); while ($zip_entry = zip_read($zip)) { // if(zip_entry_name($zip_entry)==$filename) //if you need any specified file use this condition { $fp = fopen($extract."/".zip_entry_name($zip_entry), "w"); if (zip_entry_open($zip, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp,"$buf"); zip_entry_close($zip_entry); fclose($fp); break; } } } zip_close($zip); } […]... Read More »

Yii 1.0 Update Zip files

Update Zip Files Using PHPI added the source code to add new file into existing zip files. public function actionUpdatezip($zipfilename,$filelist) { $destination=Yii::app()->basePath.'/files/'.$zipfilename.".zip"; $zip=new ZipArchive(); if(!$zip->open($destination)) { return false; } if($filelist) { foreach($filelist as $thefile) { $filemodel=new Filesmodle; $randno=rand(11111,99999); $filename=$randno.$thefile->name; // yii magic method $zip->addFile($thefile->tempname,$filename); //$fileext=$thefile->extensionName; //$filemodel->Size=$thefile->size; } } $zip->close(); }... Read More »