ProtectedFile::createFromFile PHP Method

createFromFile() public static method

Create a new protected file from an existing file.
public static createFromFile ( string $path ) : ProtectedFile
$path string Path to file
return ProtectedFile
    public static function createFromFile($path)
    {
        $file = new self();
        $file->setSource($path);
        return $file;
    }

Usage Example

 public function actionImport()
 {
     echo "<h1>Importing files:</h1>";
     foreach (glob(Yii::app()->basePath . '/data/test/*') as $src_file) {
         $file = ProtectedFile::createFromFile($src_file);
         if (!$file->save()) {
             throw new CException('Cannot save file' . print_r($file->getErrors(), true));
         }
         unlink($src_file);
         echo "<p>Imported " . $file->uid . ' - ' . $file->name . "</p>";
     }
     echo "<p>Done!</p>";
 }
All Usage Examples Of ProtectedFile::createFromFile