Yii Files Tutorials

Yii 1.0 Display Image Form Database

Before save the image into database, i created one ‘text’ field in mysql table to save the image code.We can show the image in CDetailview from database table of yii framework. Here i used showphoto_from_database() function to display the image from database. showproof_from_image_folder() is used to fetch uploaded image url from database and display.view.php <?php $this->widget('zii.widgets.CDetailView', array( 'data'=>$model, 'attributes'=>array( array( 'name'=>'photo_id', 'type'=>'raw', 'value'=>$model->showphoto_from_database(), ), array( 'name'=>'vproof_id', 'type'=>'raw', 'value'=>$model->showproof_from_image_folder(), ) ), […]... Read More »

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 »

CSV File To DB In Yii

CSV File UploadRead CSV In ControllerCSV File UploadUsing the below code i created the form “importcsvform.php”.importcsvform<div class="form"> <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'csv-form', 'enableAjaxValidation'=>false, 'htmlOptions'=>array('enctype' => 'multipart/form-data'), )); ?> <?php //echo $form->errorSummary($model); ?> <div class="row"> <?php echo $form->labelEx($model,'csvfile'); ?> <?php $this->widget('CMultiFileUpload', array( 'model'=>$model, 'name' => 'csvfile', 'max'=>1, 'accept' => 'csv', 'duplicate' => 'Duplicate file!', 'denied' => 'Invalid file type', )); ?> <?php echo $form->error($model,'csvfile'); ?> </div> <div class="row buttons"> <?php echo CHtml::submitButton('Import',array("id"=>"Import",'name'=>'Import')); […]... Read More »

Yii CMultiFileupload

PropertiesCMultifile In ViewCMultifile In controllerModel ValidationCMultiFileUpload widget functionMaximum File Size Validation On Before UploadDONT FORGET multipart/form-data <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'files-form', 'htmlOptions'=>array('enctype' => 'multipart/form-data'), ));?> PropertiesCMultiFileUpload generates a file input that can allow uploading multiple files at a time. It have the following properties.accept - Allowed file types duplicate - String message file - File name htmlOptions - additional html options id - CMultiFileUpload widget id max - max number of […]... Read More »

Yii 1.0 Delete Files

This post will help you to learn “how to delete files in yii framework”. I deleted singele file and all files from directory. Delete All Files Inside DirectoryDelete Single FileDelete Zip FilesDelete All Files Inside Directoryphp glob() method used to read all files from directory of yii application and unlink() method used to delete the files. //your directory $dir=Yii::app()->basePath.'/files/foldername/'; foreach(glob($dir.'*.*') as $files) { unlink($files); } When we use above method […]... 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 »

FTP File Transfer Using Yii

This tutorials will helpful to transfer the large files (or small files)  from ftp folder to your application folder. When you upload the large files (in applications), It will take some times. But if you use ftp file transfer It will transfer the files fast. Based on my experience i explained below.Create Ftp Account and Folder Add Ftp Extension Config Main.php Ftp Controller Ftp View Create Ftp Account and FolderFirst create a ftp account in […]... Read More »