yupe\components\behaviors\FileUploadBehavior::saveFile PHP Method

saveFile() public method

Save new uploaded file to disk and set model attribute.
public saveFile ( ) : void.
return void.
    public function saveFile()
    {
        $newFileName = $this->generateFilename();
        $this->getOwner()->setAttribute($this->attributeName, $newFileName);
        return $this->uploadManager->save($this->getUploadedFileInstance(), $this->getUploadPath(), $newFileName);
    }

Usage Example

 public function saveFile()
 {
     if (!$this->resizeOnUpload) {
         parent::saveFile();
         return;
     }
     $newFileName = $this->getFileName();
     $path = Yii::app()->uploadManager->getFilePath($newFileName, $this->getUploadPath());
     if (!YFile::checkPath(pathinfo($path, PATHINFO_DIRNAME))) {
         throw new \CHttpException(500, Yii::t('YupeModule.yupe', 'Directory "{dir}" is not acceptable for write!', array('{dir}' => $path)));
     }
     /*
             $image = Imagine::resize(
        $this->_currentFile->getTempName(),
        $this->resizeOptions['width'],
        $this->resizeOptions['height']
             );
     
             $image->save(
        $path,
        $this->resizeOptions['quality']
             );
     * 
     */
     $image = Yii::app()->image->load($this->_currentFile->getTempName())->quality($this->resizeOptions['quality']);
     $image->resize($this->resizeOptions['width'], $this->resizeOptions['height'], $this->resizeOptions['master']);
     $image->save($path);
     $this->getOwner()->{$this->attributeName} = $newFileName;
     $this->_prevFile = $this->getPrevFile();
 }
All Usage Examples Of yupe\components\behaviors\FileUploadBehavior::saveFile