Yii Framework Forum: Zip File Handling In Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Zip File Handling In Yii Rate Topic: -----

#1 User is offline   mbala 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 131
  • Joined: 21-July 12
  • Location:Chennai, Tamilnadu, India

Posted 11 September 2012 - 12:12 AM

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();
}
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,317
  • Joined: 12-October 09
  • Location:Croatia

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?
0

#3 User is offline   rha 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 10-October 11

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users