Zip Files Handler Using Yii
Create Zip Files Function
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();
}
Update Zip Function
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();
}
Delete Files in Zip Function
public function actionDeletefile($zipfilename,$filename)
{
$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();
}
Page 1 of 1
Zip File Handling In Yii
#2
Posted 11 September 2012 - 03:43 AM
There is already ZIP support in PHP - http://php.net/manual/en/book.zip.php
Find more about me.... btw. Do you know your WAN IP?
#3
Posted 07 November 2012 - 09:32 AM
Hello
In the method "CreateFile ($filename, $filelist)":
The parameter "$filelist" is an array of that type?
The parameter "$filename" seems unused, overwritten???
I tried this:
$filelist[0] = Yii::app()->file->set('one.txt', true);
$filelist[1] = Yii::app()->file->set('two.txt', true);
$this -> actionCreatefile("zipfile.zip", $filelist);
but it does not work, I get error here:
$filename = $random.$thefile;
if replacement by
$filename = $random.$thefile->filename;
and then gives me error:
$zip->addFile($thefile->tempname, $filename);
I have no property "tempname".
All this leads me to believe that $thefile is not an instance of CFile.
Also try this:
Yii::import('application.extensions.file.CFileHelper", true);
$cf_file = CFileHelper::get('one.txt');
But I get the following error:
Fatal error: Can not redeclare class CApplicationComponent in C:\xampp\htdocs\crcsoftnews\public_html\protected\extensions\file\CFileHelper.php on line 12
Any idea?
thanks
In the method "CreateFile ($filename, $filelist)":
The parameter "$filelist" is an array of that type?
The parameter "$filename" seems unused, overwritten???
I tried this:
$filelist[0] = Yii::app()->file->set('one.txt', true);
$filelist[1] = Yii::app()->file->set('two.txt', true);
$this -> actionCreatefile("zipfile.zip", $filelist);
but it does not work, I get error here:
$filename = $random.$thefile;
if replacement by
$filename = $random.$thefile->filename;
and then gives me error:
$zip->addFile($thefile->tempname, $filename);
I have no property "tempname".
All this leads me to believe that $thefile is not an instance of CFile.
Also try this:
Yii::import('application.extensions.file.CFileHelper", true);
$cf_file = CFileHelper::get('one.txt');
But I get the following error:
Fatal error: Can not redeclare class CApplicationComponent in C:\xampp\htdocs\crcsoftnews\public_html\protected\extensions\file\CFileHelper.php on line 12
Any idea?
thanks
Share this topic:
Page 1 of 1

Help













