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


PHP UploadedFile::getError方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getError方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getError方法的具体用法?PHP UploadedFile::getError怎么用?PHP UploadedFile::getError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\File\UploadedFile的用法示例。


在下文中一共展示了UploadedFile::getError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: getFileArray

 /**
  * converts UploadedFile to $_FILES array
  *
  * @return array
  */
 public function getFileArray()
 {
     $array = array('name' => $this->uploaded_file->getClientOriginalName(), 'type' => $this->uploaded_file->getClientMimeType(), 'tmp_name' => $this->uploaded_file->getPath() . $this->getOSDirectorySeparator() . $this->uploaded_file->getFilename(), 'error' => $this->uploaded_file->getError(), 'size' => $this->uploaded_file->getSize(), 'dimension' => array('width' => 0, 'height' => 0));
     if (preg_match('/^image/', $array['type'])) {
         list($array['dimension']['width'], $array['dimension']['height']) = getimagesize($this->uploaded_file);
     }
     return $array;
 }
开发者ID:RSSfeed,项目名称:UploadBundle,代码行数:13,代码来源:HandleUpload.php

示例4: testErrorIsOkByDefault

 public function testErrorIsOkByDefault()
 {
     // we can't change this setting without modifying php.ini :(
     if (ini_get('file_uploads')) {
         $file = new UploadedFile(__DIR__ . '/Fixtures/test.gif', 'original.gif', 'image/gif', filesize(__DIR__ . '/Fixtures/test.gif'), null);
         $this->assertEquals(UPLOAD_ERR_OK, $file->getError());
     }
 }
开发者ID:rooster,项目名称:symfony,代码行数:8,代码来源:UploadedFileTest.php

示例5: testErrorIsOkByDefault

    public function testErrorIsOkByDefault()
    {
        $file = new UploadedFile(
            __DIR__.'/Fixtures/test.gif',
            'original.gif',
            'image/gif',
            filesize(__DIR__.'/Fixtures/test.gif'),
            null
        );

        $this->assertEquals(UPLOAD_ERR_OK, $file->getError());
    }
开发者ID:nacef,项目名称:symfony,代码行数:12,代码来源:UploadedFileTest.php

示例6: createFromObject

 /**
  * Build a \Torann\MediaSort\File\UploadedFile object from
  * a Symfony\Component\HttpFoundation\File\UploadedFile object.
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  *
  * @return \Torann\MediaSort\File\UploadedFile
  * @throws \Torann\MediaSort\Exceptions\FileException
  */
 protected function createFromObject(SymfonyUploadedFile $file)
 {
     $path = $file->getPathname();
     $originalName = $file->getClientOriginalName();
     $mimeType = $file->getClientMimeType();
     $size = $file->getClientSize();
     $error = $file->getError();
     $uploadFile = new UploadedFile($path, $originalName, $mimeType, $size, $error);
     if (!$uploadFile->isValid()) {
         throw new FileException($uploadFile->getErrorMessage($uploadFile->getError()));
     }
     return $uploadFile;
 }
开发者ID:torann,项目名称:mediasort,代码行数:22,代码来源:FileManager.php

示例7: 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

示例8: 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

示例9: 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

示例10: handleFileUpload

 /**
  * @param UploadedFile $uploadedFile
  * @return null|string
  */
 protected function handleFileUpload($uploadedFile, $delimiter = ',', $enclosure = '"')
 {
     $errMsg = '';
     if (!$uploadedFile instanceof UploadedFile) {
         $errMsg = _("No file selected");
     } elseif ($uploadedFile->getSize() == 0 && $uploadedFile->getError() == 0) {
         $errMsg = _("Larger than upload_max_filesize ") . ini_get(self::KEY_UPLOAD_MAX_FILESIZE);
     } elseif ($uploadedFile->getClientOriginalExtension() != 'csv') {
         $errMsg = _('Invalid extension ') . $uploadedFile->getClientOriginalExtension() . ' of file ' . $uploadedFile->getClientOriginalName();
     }
     if (!empty($errMsg)) {
         return $errMsg;
     }
     /** @var LicenseCsvImport */
     $licenseCsvImport = $this->getObject('app.license_csv_import');
     $licenseCsvImport->setDelimiter($delimiter);
     $licenseCsvImport->setEnclosure($enclosure);
     return $licenseCsvImport->handleFile($uploadedFile->getRealPath());
 }
开发者ID:DanielDobre,项目名称:fossology,代码行数:23,代码来源:AdminLicenseFromCSV.php

示例11: imageUpload

 /**
  * File upload callback
  * Resizes the image according to validation constraints
  *
  * @param string                                             $field Field name
  * @param Symfony\Component\HttpFoundation\File\UploadedFile $file  File to process
  *
  * @return void
  */
 protected function imageUpload($field, UploadedFile $file)
 {
     if (UPLOAD_ERR_OK == $file->getError()) {
         $asserts = $this->getAsserts()[$field];
         foreach ($asserts as $assert) {
             // Detect image size constraints and resize accordingly
             if ($assert instanceof Image) {
                 $path = $file->getPathname();
                 $pathWithExtension = $path . '.' . $file->guessExtension();
                 rename($path, $pathWithExtension);
                 // ImageWorkshop relies on the file's extension for encoding
                 try {
                     $this->resize($pathWithExtension, $assert->maxWidth, $assert->maxHeight);
                 } catch (ImageWorkshopException $e) {
                 }
                 rename($pathWithExtension, $path);
             }
         }
     }
 }
开发者ID:neemzy,项目名称:patchwork-core,代码行数:29,代码来源:ImageModel.php

示例12: uploadFile

 /**
  * Upload a single file
  * @param UploadedFile $file
  * @return \HealthCareAbroad\MediaBundle\Entity\Media|unknown
  */
 public function uploadFile(UploadedFile $file)
 {
     if (!$file->isValid()) {
         return $file->getError();
     }
     $caption = $file->getClientOriginalName();
     $filename = $this->generateUniqueFilename($file);
     $file->move($this->uploadDirectory, $filename);
     $imageAttributes = getimagesize($this->uploadDirectory . '/' . $filename);
     $media = new Media();
     $media->setName($filename);
     $media->setContentType($imageAttributes['mime']);
     $media->setCaption($caption);
     $media->setContext(0);
     $media->setUuid(time());
     $media->setWidth($imageAttributes[0]);
     $media->setHeight($imageAttributes[1]);
     $this->entityManager->persist($media);
     $this->entityManager->flush($media);
     return $media;
 }
开发者ID:TMBaay,项目名称:MEDTrip---Healthcareabroad,代码行数:26,代码来源:MediaService.php

示例13: fromUploadFile

 /**
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  */
 public function fromUploadFile($file)
 {
     if (!empty($file)) {
         $errorCode = $file->getError();
         if ($errorCode === UPLOAD_ERR_OK) {
             $file_path = $file->getRealPath();
             $type = exif_imagetype($file_path);
             if ($type) {
                 $extension = image_type_to_extension($type);
                 $srcFilename = uniqid('js_cropper_' . time() . '_') . $extension;
                 $this->srcUrl = asset('storage/app/tmp/' . $srcFilename);
                 $srcPath = storage_path('app/tmp/' . $srcFilename);
                 if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_JPEG || $type == IMAGETYPE_PNG) {
                     if (file_exists($srcPath)) {
                         unlink($srcPath);
                     }
                     $result = move_uploaded_file($file_path, $srcPath);
                     if ($result) {
                         $this->srcPath = $srcPath;
                         $this->type = $type;
                         $this->extension = $extension;
                         return true;
                     } else {
                         $this->msg = $this->codeToMessage(UPLOAD_ERR_CANT_WRITE);
                     }
                 } else {
                     $this->msg = $this->codeToMessage(UPLOAD_ERR_EXTENSION);
                 }
             } else {
                 $this->msg = $this->codeToMessage(UPLOAD_ERR_NO_FILE);
             }
         } else {
             $this->msg = $this->codeToMessage($errorCode);
         }
     } else {
         $this->msg = $this->codeToMessage(UPLOAD_ERR_NO_FILE);
     }
     return false;
 }
开发者ID:linhntaim,项目名称:katniss,代码行数:42,代码来源:JsCropper.php

示例14: 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

示例15: testUploadErrNoFile

 public function testUploadErrNoFile()
 {
     $file = new UploadedFile('', '', null, 0, UPLOAD_ERR_NO_FILE, true);
     $this->assertEquals(0, $file->getSize());
     $this->assertEquals(UPLOAD_ERR_NO_FILE, $file->getError());
     $this->assertFalse($file->getSize(), 'SplFile::getSize() returns false on error');
     $this->assertInternalType('integer', $file->getClientSize());
     $request = new Request(array(), array(), array(), array(), array('f1' => $file, 'f2' => array('name' => null, 'type' => null, 'tmp_name' => null, 'error' => UPLOAD_ERR_NO_FILE, 'size' => 0)), array('REQUEST_METHOD' => 'POST', 'HTTP_HOST' => 'dunglas.fr', 'HTTP_X_SYMFONY' => '2.8'), 'Content');
     $psrRequest = $this->factory->createRequest($request);
     $uploadedFiles = $psrRequest->getUploadedFiles();
     $this->assertEquals(UPLOAD_ERR_NO_FILE, $uploadedFiles['f1']->getError());
     $this->assertEquals(UPLOAD_ERR_NO_FILE, $uploadedFiles['f2']->getError());
 }
开发者ID:symfony,项目名称:psr-http-message-bridge,代码行数:13,代码来源:DiactorosFactoryTest.php


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