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

getHasError() публичный Метод

public getHasError ( ) : boolean
Результат boolean whether there is an error with the uploaded file. Check [[error]] for detailed error code information.
    public function getHasError()
    {
        return $this->error != UPLOAD_ERR_OK;
    }

Usage Example

 /**
  * Загрузка изображения.
  *
  * @param UploadedFile $uploadedFile
  * @param $userId
  * @return bool
  */
 public function uploadPhoto(UploadedFile $uploadedFile, $userId)
 {
     if ($uploadedFile->getBaseName() && !$uploadedFile->getHasError()) {
         $photoName = 'profile_photo_' . $userId . '.' . $uploadedFile->getExtension();
         $photoSaveFolder = \Yii::getAlias('@app') . $this->profilePhotoFolder . '/' . $userId;
         if (!file_exists($photoSaveFolder)) {
             mkdir($photoSaveFolder);
         }
         $photoPath = $photoSaveFolder . '/' . $photoName;
         $uploadedFile->saveAs($photoPath);
         return $photoName;
     }
     return false;
 }
All Usage Examples Of yii\web\UploadedFile::getHasError