ProtectedFile::setSource PHP Method

setSource() public method

Initialise protected file from a source file.
public setSource ( string $path )
$path string
    public function setSource($path)
    {
        if (!file_exists($path) || is_dir($path)) {
            throw new CException("File doesn't exist: " . $path);
        }
        $this->_source_path = $path;
        $this->name = basename($path);
        // Set MIME type
        $path_parts = pathinfo($this->name);
        $this->mimetype = $this->lookupMimetype($path);
        // Set size
        $this->size = filesize($path);
        // UID
        $this->generateUID();
    }

Usage Example

Esempio n. 1
0
 /**
  * Create a new protected file from an existing file
  * @param string $path Path to file
  * @return ProtectedFile
  */
 public static function createFromFile($path)
 {
     $file = new ProtectedFile();
     $file->setSource($path);
     return $file;
 }