當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UploadedFile::getHasError方法代碼示例

本文整理匯總了PHP中yii\web\UploadedFile::getHasError方法的典型用法代碼示例。如果您正苦於以下問題:PHP UploadedFile::getHasError方法的具體用法?PHP UploadedFile::getHasError怎麽用?PHP UploadedFile::getHasError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\web\UploadedFile的用法示例。


在下文中一共展示了UploadedFile::getHasError方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: uploadPhoto

 /**
  * Загрузка изображения.
  *
  * @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;
 }
開發者ID:vlamug,項目名稱:landing-page-crm,代碼行數:21,代碼來源:PhotoManagerComponent.php

示例2: uploadByUploadFile

 /**
  * upload by UploadedFile instance.
  *
  * @param UploadedFile $uploadedFile Uploaded file instance
  * @param string $dir uploading file directory.
  * @param string $savePath upload file save path. If null, call [[getSavePath()]] to generate one.
  * @return File
  */
 public function uploadByUploadFile($uploadedFile, $dir, $savePath = null)
 {
     $file = new File();
     if ($uploadedFile === null) {
         $file->error = File::UPLOAD_ERROR_NO_UPLOADED_FILE;
         return $file;
     }
     // 檢查上傳文件是否有錯
     if ($uploadedFile->getHasError()) {
         $file->error = $uploadedFile->error;
         return $file;
     }
     if ($savePath !== null) {
         $dir = $this->getDir($savePath);
     }
     $type = $uploadedFile->getExtension();
     $file->error = $this->getErrors($uploadedFile->size, $dir, $type);
     if ($file->error !== UPLOAD_ERR_OK) {
         return $file;
     }
     if ($savePath === null) {
         $savePath = $this->getSavePath($dir, $type);
     }
     if ($uploadedFile->saveAs($savePath)) {
         $file->url = $this->savePath2Url($savePath);
     } else {
         $file->error = File::UPLOAD_ERROR_UPLOAD;
     }
     return $file;
 }
開發者ID:wenbin1989,項目名稱:yii2-upload,代碼行數:38,代碼來源:Uploader.php


注:本文中的yii\web\UploadedFile::getHasError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。