当前位置: 首页>>代码示例>>PHP>>正文


PHP UploadedFile::getErrorMessage方法代码示例

本文整理汇总了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;
 }
开发者ID:bmartinezteltek,项目名称:PuMuKIT2,代码行数:26,代码来源:TrackService.php

示例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;
 }
开发者ID:NewwayLibs,项目名称:uploader,代码行数:16,代码来源:Uploader.php

示例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));
     }
 }
开发者ID:sulu,项目名称:sulu,代码行数:26,代码来源:FileValidator.php

示例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;
 }
开发者ID:bmartinezteltek,项目名称:PuMuKIT2,代码行数:20,代码来源:EventPicService.php

示例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;
 }
开发者ID:netxinyi,项目名称:meigui,代码行数:17,代码来源:ImageCenterController.php

示例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;
 }
开发者ID:bmartinezteltek,项目名称:PuMuKIT2,代码行数:21,代码来源:MaterialService.php

示例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;
 }
开发者ID:bmartinezteltek,项目名称:PuMuKIT2,代码行数:26,代码来源:SeriesPicService.php

示例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');
     }
 }
开发者ID:pb199486,项目名称:Transit,代码行数:22,代码来源:UploadService.php

示例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;
 }
开发者ID:gobjila,项目名称:BackBee,代码行数:35,代码来源:ResourceController.php

示例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;
 }
开发者ID:xpressengine,项目名称:xpressengine,代码行数:35,代码来源:Storage.php

示例11: getErrorMessage

 /**
  * Returns the upload error message.
  *
  * @return string upload error
  */
 public function getErrorMessage()
 {
     return $this->uploadedFile->getErrorMessage();
 }
开发者ID:vobinh,项目名称:PHP,代码行数:9,代码来源:UploadedFile.php

示例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;
 }
开发者ID:ReissClothing,项目名称:BackBee,代码行数:25,代码来源:ResourceController.php


注:本文中的Symfony\Component\HttpFoundation\File\UploadedFile::getErrorMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。