本文整理匯總了PHP中app\models\File::getErrors方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::getErrors方法的具體用法?PHP File::getErrors怎麽用?PHP File::getErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\File
的用法示例。
在下文中一共展示了File::getErrors方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: saveFileToStorage
/**
* Saves file to a random folder
* @param \stdClass $fileData, example:
* object(stdClass)[82]
* public 'name' => string 'SampleVideo_1080x720_20mb (1).mp4' (length=33)
* public 'size' => int 21069678
* public 'type' => string 'video/mp4' (length=9)
* public 'extension' => string 'mp4' (length=3)
*
* @return int File record id
* @author Alex Makhorin
*/
public function saveFileToStorage($fileData)
{
$tmpFilePath = $this->tmpDirectory . $fileData->name;
$randomDir = $this->generateRandomDirectory($fileData->name);
$randomName = $this->generateRandomName();
$newPath = $this->storageDirectory . $randomDir . '/' . $randomName . '.' . $fileData->extension;
$this->createFolders($newPath);
rename($tmpFilePath, $newPath);
$url = $this->storageUrl . $randomDir . '/' . $randomName . '.' . $fileData->extension;
if (strpos($fileData->type, 'video/') === 0) {
$type = FileType::TYPE_VIDEO;
} elseif (strpos($fileData->type, 'image/') === 0) {
$type = FileType::TYPE_IMAGE;
} else {
is_file($newPath) && unlink($newPath);
throw new HttpException(400, 'No data to handle');
}
$file = new File();
$file->file_type = $type;
$file->mime_type = $fileData->type;
$file->url = $url;
$isSaved = $file->save();
if (!$isSaved) {
throw new HttpException(500, 'DB error occured: ' . \yii\helpers\VarDumper::dumpAsString($file->getErrors()));
}
return $file->primaryKey;
}