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


PHP File::getFilename方法代码示例

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


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

示例1: getName

 /**
  * Get original name of file.
  *
  * @return string
  */
 public function getName()
 {
     if ($this->file instanceof UploadedFile) {
         return $this->file->getClientOriginalName();
     }
     return $this->file->getFilename();
 }
开发者ID:Vooodoo,项目名称:MediaBundle,代码行数:12,代码来源:FileInfo.php

示例2: saveImg

 /**
  * @param \Symfony\Component\HttpFoundation\File\File $img
  * @param string                                      $path
  *
  * @return string
  */
 public function saveImg(File $img, $path)
 {
     $imageLib = new ImageLib();
     $imageLib->load($path . $img->getFilename());
     $outputImgName = md5($img->getFilename() . time()) . '.' . $img->getExtension();
     //$imageLib->resizeImage(100, 100, array('crop', 'tr'), true);
     $imageLib->saveImage($path . $outputImgName, 100);
     return $outputImgName;
 }
开发者ID:yasoon,项目名称:yasoon,代码行数:15,代码来源:ImageService.php

示例3: buildView

 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $configs = $form->getAttribute('configs');
     $datas = $form->getClientData();
     if (!empty($datas)) {
         if ($form->getAttribute('multiple')) {
             $datas = is_scalar($datas) ? explode(',', $datas) : $datas;
             $value = array();
             foreach ($datas as $data) {
                 if (!$data instanceof File) {
                     $data = new File($form->getAttribute('rootDir') . '/' . $data);
                 }
                 $value[] = $configs['folder'] . '/' . $data->getFilename();
             }
             $value = implode(',', $value);
         } else {
             if (!$datas instanceof File) {
                 $datas = new File($form->getAttribute('rootDir') . '/' . $datas);
             }
             $value = $configs['folder'] . '/' . $datas->getFilename();
         }
         $view->set('value', $value);
     }
     $view->set('type', 'hidden')->set('configs', $form->getAttribute('configs'));
 }
开发者ID:r4cker,项目名称:GenemuFormBundle,代码行数:28,代码来源:FileType.php

示例4: getResponse

 /**
  * @param Closure $callback
  * @param InterventionRequest $interventionRequest
  * @return Response
  */
 public function getResponse(Closure $callback, InterventionRequest $interventionRequest)
 {
     try {
         $this->cacheFile = new File($this->cacheFilePath);
         $response = new Response(file_get_contents($this->cacheFile->getPathname()), Response::HTTP_OK, ['Content-Type' => $this->cacheFile->getMimeType(), 'Content-Disposition' => 'filename="' . $this->realImage->getFilename() . '"', 'X-Generator-Cached' => true]);
         $response->setLastModified(new \DateTime(date("Y-m-d H:i:s", $this->cacheFile->getMTime())));
     } catch (FileNotFoundException $e) {
         if (is_callable($callback)) {
             $image = $callback($interventionRequest);
             if ($image instanceof Image) {
                 $this->saveImage($image);
                 $this->cacheFile = new File($this->cacheFilePath);
                 if (null !== $this->dispatcher) {
                     // create the ImageSavedEvent and dispatch it
                     $event = new ImageSavedEvent($image, $this->cacheFile);
                     $this->dispatcher->dispatch(ImageSavedEvent::NAME, $event);
                 }
                 // send HTTP header and output image data
                 $response = new Response(file_get_contents($this->cacheFile->getPathname()), Response::HTTP_OK, ['Content-Type' => $image->mime(), 'Content-Disposition' => 'filename="' . $this->realImage->getFilename() . '"', 'X-Generator-First-Render' => true]);
                 $response->setLastModified(new \DateTime('now'));
             } else {
                 throw new \RuntimeException("Image is not a valid InterventionImage instance.", 1);
             }
         } else {
             throw new \RuntimeException("No image handle closure defined", 1);
         }
     }
     $this->initializeGarbageCollection();
     return $response;
 }
开发者ID:ambroisemaupate,项目名称:intervention-request,代码行数:35,代码来源:FileCache.php

示例5: handle

 /**
  * Handle request to convert it to a Response object.
  */
 public function handle()
 {
     try {
         if (!$this->request->query->has('image')) {
             throw new FileNotFoundException("No valid image path found in URI", 1);
         }
         $nativePath = $this->configuration->getImagesPath() . '/' . $this->request->query->get('image');
         $this->nativeImage = new File($nativePath);
         $this->parseQuality();
         if ($this->configuration->hasCaching()) {
             $cache = new FileCache($this->request, $this->nativeImage, $this->configuration->getCachePath(), $this->logger, $this->quality, $this->configuration->getTtl(), $this->configuration->getGcProbability(), $this->configuration->getUseFileChecksum());
             $cache->setDispatcher($this->dispatcher);
             /** @var Response response */
             $this->response = $cache->getResponse(function (InterventionRequest $interventionRequest) {
                 return $interventionRequest->processImage();
             }, $this);
         } else {
             $this->processImage();
             $this->response = new Response((string) $this->image->encode(null, $this->quality), Response::HTTP_OK, ['Content-Type' => $this->image->mime(), 'Content-Disposition' => 'filename="' . $this->nativeImage->getFilename() . '"', 'X-Generator-First-Render' => true]);
             $this->response->setLastModified(new \DateTime('now'));
         }
     } catch (FileNotFoundException $e) {
         $this->response = $this->getNotFoundResponse($e->getMessage());
     } catch (\RuntimeException $e) {
         $this->response = $this->getBadRequestResponse($e->getMessage());
     }
 }
开发者ID:ambroisemaupate,项目名称:intervention-request,代码行数:30,代码来源:InterventionRequest.php

示例6: getSplitFiles

 /**
  * @return array
  */
 public function getSplitFiles()
 {
     $file = new File($this->archivePath);
     $finder = new Finder();
     $finder->files()->in(dirname($this->archivePath))->notName($file->getFilename())->sortByModifiedTime();
     return iterator_to_array($finder);
 }
开发者ID:ronisaha,项目名称:CloudBackupBundle,代码行数:10,代码来源:BaseSplitter.php

示例7: setFileAttribute

 public function setFileAttribute(\Symfony\Component\HttpFoundation\File\File $file)
 {
     $this->attributes['file'] = $file;
     $this->original_name = $file instanceof UploadedFile ? $file->getClientOriginalName() : $file->getFilename();
     $this->size = $file->getSize();
     $this->content_type = $file->getMimeType();
 }
开发者ID:AniartUA,项目名称:crm,代码行数:7,代码来源:File.php

示例8: setContentDisposition

 /**
  * Sets the Content-Disposition header with the given filename.
  *
  * @param string $disposition      ResponseHeaderBag::DISPOSITION_INLINE or ResponseHeaderBag::DISPOSITION_ATTACHMENT
  * @param string $filename         Optionally use this filename instead of the real name of the file
  * @param string $filenameFallback A fallback filename, containing only ASCII characters. Defaults to an automatically encoded filename
  *
  * @return BinaryFileResponse
  */
 public function setContentDisposition($disposition, $filename = '', $filenameFallback = '')
 {
     if ($filename === '') {
         $filename = $this->file->getFilename();
     }
     $dispositionHeader = $this->headers->makeDisposition($disposition, $filename, $filenameFallback);
     $this->headers->set('Content-Disposition', $dispositionHeader);
     return $this;
 }
开发者ID:tifabien,项目名称:symfony,代码行数:18,代码来源:BinaryFileResponse.php

示例9: setImageFile

 /**
  * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  * must be able to accept an instance of 'File' as the bundle will inject one here
  * during Doctrine hydration.
  *
  * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  *
  * @return $this
  */
 public function setImageFile(File $image = null)
 {
     $this->imageFile = $image;
     if ($image) {
         $this->modifiedAt = new \DateTime('now');
         $this->fileName = $image->getFilename();
     }
     return $this;
 }
开发者ID:nass59,项目名称:Lab,代码行数:20,代码来源:Image.php

示例10: setImageFile

 public function setImageFile(File $imageFile)
 {
     if ($imageFile instanceof File) {
         $this->imageFile = $imageFile;
         if (!$this->name) {
             $this->name = $imageFile->getFilename();
         }
         $this->updatedAt = new \DateTime('now');
     }
 }
开发者ID:odiseoteam,项目名称:odiseo-team-website,代码行数:10,代码来源:PostImage.php

示例11: transform

 /**
  * @inheritDoc
  */
 public function transform(File $file, ResourceAnnotationInterface $config)
 {
     /** @var  ResourceImage $config */
     //create copy with image extension instead of .tmp, required to save with Imagine
     $newName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $file->getFilename() . '.' . $file->guessExtension();
     if (copy($file->getRealPath(), $newName)) {
         $newFile = new File($newName);
         return $this->imageResize($newFile, $config->maxWith, $config->maxHeight, $config->enlarge, $config->keepRatio);
     } else {
         return $file;
     }
 }
开发者ID:rafrsr,项目名称:resource-bundle,代码行数:15,代码来源:ImageTransformer.php

示例12: fromFile

 /**
  * Creates a file object from a file on the disk.
  */
 public function fromFile($filePath)
 {
     if ($filePath === null) {
         return;
     }
     $file = new FileObj($filePath);
     $this->file_name = $file->getFilename();
     $this->file_size = $file->getSize();
     $this->content_type = $file->getMimeType();
     $this->disk_name = $this->getDiskName();
     $this->putFile($uploadedFile->getRealPath(), $this->disk_name);
 }
开发者ID:tamboer,项目名称:LaravelOctober,代码行数:15,代码来源:File.php

示例13: setAvatarFile

 /**
  * Set the avatar of the object to be a specific file
  *
  * @param  File|null $file The avatar file
  * @return self
  */
 public function setAvatarFile($file)
 {
     if ($file) {
         // We don't use File's fread() because it's unavailable in less
         // recent PHP versions
         $path = $file->getPath() . '/' . $file->getFilename();
         $content = file_get_contents($path);
         $path = $this->getAvatarPath(null, false, false);
         $filename = $this->getAvatarFileName($content);
         $file->move(DOC_ROOT . $path, $filename);
         $this->setAvatar($path . $filename);
     }
     return $this;
 }
开发者ID:blast007,项目名称:bzion,代码行数:20,代码来源:AvatarModel.php

示例14: validateFileExtension

 public static function validateFileExtension(File $file, $extensions = array())
 {
     if (empty($extensions)) {
         $extensions = self::getSecureFileExtensions();
     }
     if ($file instanceof UploadedFile) {
         $filename = $file->getClientOriginalName();
     } else {
         $filename = $file->getFilename();
     }
     $errors = array();
     $regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
     if (!preg_match($regex, $filename)) {
         $errors[] = "只允许上传以下扩展名的文件:" . $extensions;
     }
     return $errors;
 }
开发者ID:liugang19890719,项目名称:www.zesow.com,代码行数:17,代码来源:FileToolkit.php

示例15: prepareResponse

 private function prepareResponse(File $file, $filename = null)
 {
     $mimeType = $file->getMimeType();
     if ($mimeType == 'application/pdf') {
         $disposition = 'inline';
     } else {
         $disposition = 'attachment';
     }
     $response = new Response();
     $response->headers->set('Cache-Control', 'private');
     $response->headers->set('Content-Type', $mimeType);
     $response->headers->set('Content-Disposition', $disposition . '; filename="' . ($filename ? $filename : $file->getFilename()) . '"');
     $response->headers->set('Content-Length', $file->getSize());
     $response->sendHeaders();
     readfile($file);
     return $response;
 }
开发者ID:junjinZ,项目名称:wealthbot,代码行数:17,代码来源:FilesController.php


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