Showing posts with label Yii Files. Show all posts
Showing posts with label Yii Files. Show all posts

Tuesday, July 10, 2012

Yii Hint For Files Handling

Files

Delete All Files Inside Directory Now All files will delete inside directory
Delete Single File Using File Path
Read More...

Yii Zip Format Function

Create Zip Files in Yii


Extract Zip Files in Yii


Download Zip Files in Yii

Delete Zip Files in Yii


Read More...

Friday, May 18, 2012

Multifile upload in yii

CMultifile Upload: index.php[view]


CMultifile Upload: filecontroller.php[controller]

Save this file as zip into your directory Write following code in controller
Read More...

Monday, May 7, 2012

Update Zip files in yii

Update Zip Files Using PHP

I added the source code to add new file into existing zip files.
SourceCode:
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...

Extract zip files in yii

Extract Zip Files Using Yii

I added the source code to extract the zip files using yii
SourceCode:
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...

Create zip file in yii

Create Zip Files Using PHP

I 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...

Download Zip files in yii

Download Zip Files Using Yii

Here i 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: $ctype="application/force-download"; 
            } 
            $newpath=$extract.'/'.$filename;    
            header("Pragma: public");
            header("Content-Type: application/$ctype");
            header("Content-Disposition: inline; filename=$docname");
            header('Content-Length: '.filesize($filename));
            header("Accept Ranges: bytes");
            header("Expires: 0"); 
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
            readfile("$filename");
        }
       else
       {
        echo "error";
       }
   }
Read More...

Delete zip file in yii

Delete Zip Files Using PHP

Here 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...