yii\web\UploadedFile::saveAs PHP Метод

saveAs() публичный метод

Note that this method uses php's move_uploaded_file() method. If the target file $file already exists, it will be overwritten.
См. также: error
public saveAs ( string $file, boolean $deleteTempFile = true ) : boolean
$file string the file path used to save the uploaded file
$deleteTempFile boolean whether to delete the temporary file after saving. If true, you will not be able to save the uploaded file again in the current request.
Результат boolean true whether the file is saved successfully
    public function saveAs($file, $deleteTempFile = true)
    {
        if ($this->error == UPLOAD_ERR_OK) {
            if ($deleteTempFile) {
                return move_uploaded_file($this->tempName, $file);
            } elseif (is_uploaded_file($this->tempName)) {
                return copy($this->tempName, $file);
            }
        }
        return false;
    }

Usage Example

Пример #1
5
 public function afterSave($insert, $changedAttributes)
 {
     $this->preview_input = UploadedFile::getInstance($this, 'preview_input');
     if (!empty($this->preview_input)) {
         $this->preview_input->saveAs($this->preview_picture);
     }
     parent::afterSave($insert, $changedAttributes);
 }
All Usage Examples Of yii\web\UploadedFile::saveAs