本文整理匯總了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;
}
示例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;
}