當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。