本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getErrorMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getErrorMessage方法的具体用法?PHP UploadedFile::getErrorMessage怎么用?PHP UploadedFile::getErrorMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getErrorMessage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createTrackFromLocalHardDrive
/**
* Create track from local hard drive with job service
*
* @param MultimediaObject $multimediaObject
* @param UploadedFile $file
* @param string $profile
* @param int $priority
* @param string $language
* @param array $description
* @return MultimediaObject
*/
public function createTrackFromLocalHardDrive(MultimediaObject $multimediaObject, UploadedFile $trackFile, $profile, $priority, $language, $description)
{
if (null === $this->profileService->getProfile($profile)) {
throw new \Exception("Can't find given profile with name " . $profile);
}
if (UPLOAD_ERR_OK != $trackFile->getError()) {
throw new \Exception($trackFile->getErrorMessage());
}
if (!is_file($trackFile->getPathname())) {
throw new FileNotFoundException($trackFile->getPathname());
}
$pathFile = $trackFile->move($this->tmpPath . "/" . $multimediaObject->getId(), $trackFile->getClientOriginalName());
$this->jobService->addJob($pathFile, $profile, $priority, $multimediaObject, $language, $description);
return $multimediaObject;
}
示例2: init
/**
* @param UploadedFile $file
*
* @return Uploader
*
* @throws UploaderException
*/
public function init(UploadedFile $file)
{
// check if file correct
if (!$file->isValid()) {
throw new UploaderException($file->getErrorMessage());
}
$this->file = $file;
return $this;
}
示例3: validate
/**
* @param UploadedFile $file
* @param array $methods
*
* @return mixed|void
*
* @throws InvalidFileTypeException
* @throws InvalidFileException
* @throws UploadFileNotSetException
* @throws MaxFileSizeExceededException
*/
public function validate(UploadedFile $file, $methods = [self::VALIDATOR_FILE_SET, self::VALIDATOR_FILE_ERRORS, self::VALIDATOR_BLOCK_FILE_TYPES, self::VALIDATOR_MAX_FILE_SIZE])
{
if (in_array(self::VALIDATOR_FILE_ERRORS, $methods) && $file->getError() > 0) {
throw new InvalidFileException(sprintf('The file upload had an error("%s: %s")', $file->getError(), $file->getErrorMessage()));
}
if (in_array(self::VALIDATOR_FILE_SET, $methods) && $file->getFilename() == '') {
throw new UploadFileNotSetException(sprintf('No file "%s" was set', $file->getFilename()));
}
if (in_array(self::VALIDATOR_BLOCK_FILE_TYPES, $methods) && in_array($file->getMimeType(), $this->blockedMimeTypes)) {
throw new InvalidFileTypeException(sprintf('The file type "%s" was blocked', $file->getMimeType()));
}
if (in_array(self::VALIDATOR_MAX_FILE_SIZE, $methods) && $this->maxFileSize !== null && $file->getSize() >= $this->maxFileSize) {
throw new MaxFileSizeExceededException(sprintf('File "%s" exceeds the configured maximum filesize of "%s"', $file->getFilename(), $this->maxFilesize));
}
}
示例4: addPicFile
/**
* Set a pic from an url into the event
*/
public function addPicFile(Event $event, UploadedFile $picFile)
{
if (UPLOAD_ERR_OK != $picFile->getError()) {
throw new \Exception($picFile->getErrorMessage());
}
if (!is_file($picFile->getPathname())) {
throw new FileNotFoundException($picFile->getPathname());
}
$path = $picFile->move($this->targetPath . "/" . $event->getId(), $picFile->getClientOriginalName());
$pic = new Pic();
$pic->setUrl(str_replace($this->targetPath, $this->targetUrl, $path));
$pic->setPath($path);
$event->setPic($pic);
$this->dm->persist($event);
$this->dm->flush();
return $event;
}
示例5: checkFile
protected function checkFile(UploadedFile $file)
{
$mime = $file->getClientMimeType();
$info = array('name' => $file->getClientOriginalName(), 'size' => $file->getClientSize(), 'mime' => $mime, 'extension' => $file->getClientOriginalExtension(), 'type' => $mime, 'error' => '');
if ($file->isValid()) {
if (!$info['type']) {
$info['status'] = 9;
$info['error'] = '不支持的文件类型';
} else {
$info['status'] = UPLOAD_ERR_OK;
}
} else {
$info['status'] = $file->getError();
$info['error'] = $file->getErrorMessage();
}
return $info;
}
示例6: addMaterialFile
/**
* Add a material from a file into the multimediaObject
*/
public function addMaterialFile(MultimediaObject $multimediaObject, UploadedFile $materialFile, $formData)
{
if (UPLOAD_ERR_OK != $materialFile->getError()) {
throw new \Exception($materialFile->getErrorMessage());
}
if (!is_file($materialFile->getPathname())) {
throw new FileNotFoundException($materialFile->getPathname());
}
$material = new Material();
$material = $this->saveFormData($material, $formData);
$path = $materialFile->move($this->targetPath . "/" . $multimediaObject->getId(), $materialFile->getClientOriginalName());
$material->setPath($path);
$material->setUrl(str_replace($this->targetPath, $this->targetUrl, $path));
$multimediaObject->addMaterial($material);
$this->dm->persist($multimediaObject);
$this->dm->flush();
return $multimediaObject;
}
示例7: addPicFile
/**
* Set a pic from an url into the series
*/
public function addPicFile(Series $series, UploadedFile $picFile, $isBanner = false, $bannerTargetUrl = "")
{
if (UPLOAD_ERR_OK != $picFile->getError()) {
throw new \Exception($picFile->getErrorMessage());
}
if (!is_file($picFile->getPathname())) {
throw new FileNotFoundException($picFile->getPathname());
}
$path = $picFile->move($this->targetPath . "/" . $series->getId(), $picFile->getClientOriginalName());
$pic = new Pic();
$pic->setUrl(str_replace($this->targetPath, $this->targetUrl, $path));
$pic->setPath($path);
if ($isBanner) {
$pic->setHide(true);
$pic->addTag('banner');
$series = $this->addBanner($series, $pic->getUrl(), $bannerTargetUrl);
}
// TODO: add pic the latest if it is banner
$series->addPic($pic);
$this->dm->persist($series);
$this->dm->flush();
return $series;
}
示例8: validateUploadedFile
/**
* @param UploadedFile $uploadedFile
* @throws InvalidUploadException
* @throws MaxFileSizeExceededException
* @throws InvalidExtensionException
* @throws InvalidMimeTypeException
*/
protected function validateUploadedFile(UploadedFile $uploadedFile)
{
if (!$uploadedFile->isValid()) {
throw new InvalidUploadException($uploadedFile->getErrorMessage());
}
if ($this->maxUploadSize() < $uploadedFile->getSize()) {
throw new MaxFileSizeExceededException('Uploaded file exceeded maximum allowed upload size.');
}
if (!in_array($uploadedFile->getExtension(), $this->allowedExtensions())) {
throw new InvalidExtensionException('Files with extension (' . $uploadedFile->getExtension() . ') are not allowed');
}
if (!in_array($uploadedFile->getMimeType(), $this->allowedMimeTypes())) {
throw new InvalidMimeTypeException('Files with mime type (' . $uploadedFile->getMimeType() . ' are not allowed');
}
}
示例9: doRequestUpload
/**
* Upload file from the request
*
* @param UploadedFile $file
* @return Array $data Retrieve into the content of response
* @throws BadRequestHttpException The file is too big
*/
private function doRequestUpload(UploadedFile $file)
{
$tmpDirectory = $this->getApplication()->getTemporaryDir();
$data = [];
if (null !== $file) {
if ($file->isValid()) {
if ($file->getClientSize() <= $file->getMaxFilesize()) {
$data = $this->buildData($file->getClientOriginalName(), $file->guessExtension());
$file->move($tmpDirectory, $data['filename']);
$data['size'] = round($file->getClientSize() / 1024, 2);
if ($imageInfo = @getimagesize($data['path'])) {
if (isset($imageInfo[0]) && isset($imageInfo[1])) {
$data['width'] = $imageInfo[0];
$data['height'] = $imageInfo[1];
}
} else {
$data['width'] = 0;
$data['height'] = 0;
}
} else {
throw new BadRequestHttpException('Too big file, the max file size is ' . $file->getMaxFilesize());
}
} else {
throw new BadRequestHttpException($file->getErrorMessage());
}
}
return $data;
}
示例10: upload
/**
* file upload to storage
*
* @param UploadedFile $uploaded uploaded file instance
* @param string $path be saved path
* @param string|null $name be saved file name
* @param string|null $disk disk name (ex. local, ftp, s3 ...)
* @param UserInterface $user user instance
* @return File
*/
public function upload(UploadedFile $uploaded, $path, $name = null, $disk = null, UserInterface $user = null)
{
if ($uploaded->isValid() === false) {
throw new InvalidFileException(['name' => $uploaded->getClientOriginalName(), 'detail' => $uploaded->getErrorMessage()]);
}
$id = $this->keygen->generate();
$name = $name ?: $this->makeFilename($uploaded->getClientOriginalName());
$path = $this->makePath($id, $path);
$disk = $disk ?: $this->distributor->allot($uploaded);
$user = $user ?: $this->auth->user();
if (!$this->files->store(file_get_contents($uploaded->getPathname()), $path . '/' . $name, $disk)) {
throw new WritingFailException();
}
$file = $this->createModel();
$file->id = $id;
$file->userId = $user->getId();
$file->disk = $disk;
$file->path = $path;
$file->filename = $name;
$file->clientname = $uploaded->getClientOriginalName();
$file->mime = $uploaded->getMimeType();
$file->size = $uploaded->getSize();
$file->save();
return $file;
}
示例11: getErrorMessage
/**
* Returns the upload error message.
*
* @return string upload error
*/
public function getErrorMessage()
{
return $this->uploadedFile->getErrorMessage();
}
示例12: doRequestUpload
/**
* Upload file from the request
*
* @param UploadedFile $file
* @return Array $data Retrieve into the content of response
* @throws BadRequestHttpException The file is too big
*/
private function doRequestUpload(UploadedFile $file)
{
$tmpDirectory = $this->getParameter("kernel.cache_dir");
$data = [];
if (null !== $file) {
if ($file->isValid()) {
if ($file->getClientSize() <= $file->getMaxFilesize()) {
$data = $this->buildData($file->getClientOriginalName(), $file->guessExtension());
$file->move($tmpDirectory, $data['filename']);
} else {
throw new BadRequestHttpException('Too big file, the max file size is ' . $file->getMaxFilesize());
}
} else {
throw new BadRequestHttpException($file->getErrorMessage());
}
}
return $data;
}