本文整理汇总了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;
}