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 Directory

php glob() method used to read all files from directory of yii application and unlink() method used to delete the files.

//your directory                                
foreach(glob($dir.'*.*') as $files)
When we use above method , All files will be deleted inside directory

Delete Single File

Get the base directory of yii application using Yii::app()->basePath and assign the folder path, file path to delete the file. apply unlink() to delete the file.

//your file path

Delete Zip Files

Here i added this code to delete the zip files inside the folder of yii framework.

public function actionDeletefile($id,$docid)
    $zip = new ZipArchive;
    if ($zip->open($filepath) === TRUE) 
        $zip->deleteName($filename); // this file of inside zip folder     
    } else{