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


PHP File::getExtension方法代码示例

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


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

示例1: buildView

 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     parent::buildView($view, $form, $options);
     $data = $form->getData();
     if (is_string($data)) {
         $data = ['filename' => basename($data), 'url' => $data];
     }
     if (is_array($data)) {
         if (!isset($view->var['url']) && isset($data['url'])) {
             $view->vars['url'] = $data['url'];
         }
         if (!isset($view->var['filename']) && isset($data['filename'])) {
             $view->vars['filename'] = $data['filename'];
         }
     }
     // autodetect type of upload
     $uploadtype = $options['uploadtype'];
     if (isset($view->vars['filename'])) {
         $file = new File($view->vars['filename'], false);
         $view->vars['filetype'] = $file->getExtension();
         switch ($file->getExtension()) {
             case 'png':
             case 'jpg':
             case 'jpeg':
             case 'gif':
                 $uploadtype = 'image';
                 break;
             case 'mp4':
                 $uploadtype = 'video';
                 break;
             case 'mp3':
             case 'm4v':
                 $uploadtype = 'audio';
                 break;
             default:
                 break;
         }
     }
     $view->vars['uploadtype'] = $uploadtype;
     $view->vars['placeholdWidth'] = $options['placeholdWidth'];
     $view->vars['placeholdHeight'] = $options['placeholdHeight'];
     $view->vars['placeholdText'] = $options['placeholdText'];
     $view->vars['ratio'] = $options['ratio'];
     $view->vars['remove'] = $options['remove'];
     $pattern = $options['pattern'];
     if ($pattern != null) {
         if (!$this->container->hasParameter($pattern)) {
             throw new \Exception('You must define an existing pattern');
         }
         $patternSize = $this->container->getParameter($pattern);
         $view->vars['label'] .= ' (Max width: ' . $patternSize['width'] . ', Max height: ' . $patternSize['height'] . ')';
     }
 }
开发者ID:nmariani,项目名称:bootstrapp-bundle,代码行数:56,代码来源:FileType.php

示例2: generateRelativePath

 /**
  * @param Contribution $contribution
  * @param File         $file
  *
  * @return string
  */
 public function generateRelativePath(Contribution $contribution, File $file)
 {
     $path = $contribution->getAuthProvider() . DIRECTORY_SEPARATOR;
     $path .= $contribution->getIdentifier();
     $path .= '.' . ($file->guessExtension() ?: $file->getExtension());
     return $path;
 }
开发者ID:rcambien,项目名称:haphpy-birthday,代码行数:13,代码来源:PathGenerator.php

示例3: getExtension

 /**
  * Use Symfony components to guess the file extension.
  *
  * @return string
  *         File extension
  */
 public function getExtension()
 {
     if (!is_null($this->extension)) {
         return $this->extension;
     }
     return $this->extension = $this->info->getExtension() ?: $this->info->guessExtension();
 }
开发者ID:fuzz-productions,项目名称:image-resizer,代码行数:13,代码来源:File.php

示例4: boot

 protected static function boot()
 {
     parent::boot();
     static::updating(function ($model) {
         $changed = $model->getDirty();
         if (isset($changed['name'])) {
             $slug = $model->gallery->slug;
             $path = public_path() . '/gallery_assets/galleries/' . $slug;
             //Get old file
             $oldPath = $path . '/' . $model->file;
             $file = new File($oldPath);
             //Set the new file with original extension
             $newName = strtolower(str_slug($model->name) . '_' . str_random(5)) . '.' . $file->getExtension();
             $renamed = $path . '/' . $newName;
             //Rename asset
             if (rename($file, $renamed)) {
                 $model->setAttribute('file', $newName);
                 return true;
             } else {
                 return false;
             }
         }
         return true;
     });
     static::deleting(function ($model) {
         $slug = $model->gallery->slug;
         $path = public_path() . '/gallery_assets/galleries/' . $slug;
         $oldPath = $path . '/' . $model->file;
         $file = new File($oldPath);
         @unlink($file);
         //@ to prevent errors
         return true;
     });
 }
开发者ID:Krato,项目名称:kgallery,代码行数:34,代码来源:PhotoEvents.php

示例5: getExtension

 protected function getExtension()
 {
     $extension = 'jpg';
     if (in_array(strtolower($this->realImage->getExtension()), static::$allowedExtensions)) {
         $extension = strtolower($this->realImage->getExtension());
     }
     return $extension;
 }
开发者ID:ambroisemaupate,项目名称:intervention-request,代码行数:8,代码来源:FileCache.php

示例6: getFilename

 /**
  * Calculate the filename of the resultant file or version.
  *
  * @param File        $original The original file
  * @param string|null $version  The name of the version, or null
  *
  * @return string The resultant filename
  */
 public function getFilename(File $original, $version = null)
 {
     if (is_null($version)) {
         return $original->getBasename();
     }
     $extension = $original->getExtension();
     $base = $original->getBasename($extension);
     return $base . $version . '.' . $extension;
 }
开发者ID:clarkf,项目名称:hitch,代码行数:17,代码来源:Uploader.php

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

示例8: replaceFromFilesystem

 /**
  * Replaces the current file with a new file.
  *
  * @param UploadedFile $file           The target file
  * @param File         $filesystemFile The source file
  */
 public function replaceFromFilesystem(UploadedFile $file, File $filesystemFile)
 {
     $file->setOriginalFilename($filesystemFile->getBasename());
     $file->setExtension($filesystemFile->getExtension());
     $file->setMimeType($filesystemFile->getMimeType());
     $file->setSize($filesystemFile->getSize());
     $storage = $this->getStorage($file);
     if ($filesystemFile->getSize() > $this->container->get("partkeepr_systemservice")->getFreeDiskSpace()) {
         throw new DiskSpaceExhaustedException();
     }
     $storage->write($file->getFullFilename(), file_get_contents($filesystemFile->getPathname()), true);
 }
开发者ID:fulcrum3d,项目名称:PartKeepr,代码行数:18,代码来源:UploadedFileService.php

示例9: visualizar_archivo

 /**
  * @param $filename
  *
  * @return string
  */
 public function visualizar_archivo($filename = null)
 {
     if ($filename) {
         $pathFile = $this->uploads_directory_name . '/' . $filename;
         $file = new File($pathFile);
         $img = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'pjpeg'];
         if (in_array($file->getExtension(), $img)) {
             return '<img src="' . $this->packages->getUrl($pathFile) . '" height="60">';
         }
         return '<a href="' . $this->packages->getUrl($pathFile) . '" download>Descargar archivo</a>';
     }
 }
开发者ID:JuanLuisGarciaBorrego,项目名称:emergya,代码行数:17,代码来源:TablonExtension.php

示例10: getFile

 /**
  * @param string $path Path to the file
  *
  * @return Response
  */
 public function getFile($path)
 {
     if (is_file($path)) {
         $file = new File($path);
         $fileContent = file_get_contents($path);
         $response = new Response($fileContent);
         $response->headers->set('Content-Type', $this->getContentType($file->getExtension()));
         $response->setCharset('UTF-8');
         return $response;
     }
     return new Response('File not found', 404);
 }
开发者ID:Ard-Jan,项目名称:silex-swagger-ui,代码行数:17,代码来源:SwaggerUIServiceProvider.php

示例11: sendFile

 protected function sendFile(Gitiki $gitiki, $file, $responseClass)
 {
     try {
         $fileInfo = new File(__DIR__ . '/../Resources/highlightjs/' . $file);
     } catch (FileNotFoundException $e) {
         $gitiki->abort(404, 'The file "%s" does not exists');
     }
     $response = new $responseClass($fileInfo);
     $request = $gitiki['request'];
     $response->headers->set('content-type', $request->getMimeType($fileInfo->getExtension()));
     $response->setMaxAge(0)->isNotModified($request);
     return $response;
 }
开发者ID:gitiki,项目名称:code-highlight,代码行数:13,代码来源:AssetsController.php

示例12: execute

 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When the target directory does not exist
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->getContainer()->get('kernel')->getRootDir();
     $targetArg = rtrim($input->getArgument('target'), '/') . '/';
     $rootDir = $this->getContainer()->get('kernel')->getRootDir();
     $targetDir = $rootDir . '/../' . $targetArg;
     $confDir = $rootDir . '/config';
     if (!is_dir($targetDir)) {
         throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
     }
     if (!file_exists($confDir . '/assets.json')) {
         throw new \InvalidArgumentException('The file ' . $confDir . '/assets.json does not exist.');
     }
     $output->writeln("Combining assets");
     $assetsFiles = json_decode(file_get_contents($confDir . '/assets.json'), true);
     foreach ($assetsFiles as $type => $combined) {
         foreach ($combined as $name => $files) {
             file_put_contents($targetDir . $files['output'], '');
             $this->assets[$type][$name] = (array) $files['input'];
             foreach ($this->assets[$type][$name] as $value) {
                 file_put_contents($targetDir . $files['output'], file_get_contents($targetDir . $value), FILE_APPEND);
             }
             $file = $targetDir . $files['output'];
             if (is_file($file)) {
                 $f = new File($file);
                 switch ($f->getExtension()) {
                     case 'css':
                         $resource = new AssetCollection(array(new FileAsset($file)), array(new MinifyCssCompressorFilter()));
                         $resource->load();
                         file_put_contents($file, $resource->dump());
                         $output->writeln(sprintf('File <comment>%s</comment> was combined and minified', $file));
                         break;
                     case 'js':
                         $resource = new AssetCollection(array(new FileAsset($file)), array(new JSMinPlusFilter()));
                         $resource->load();
                         file_put_contents($file, $resource->dump());
                         $output->writeln(sprintf('File <comment>%s</comment> was combined and minified', $file));
                         break;
                 }
             }
         }
     }
 }
开发者ID:eab-dev,项目名称:SemaMinifierBundle,代码行数:48,代码来源:AssetsCombineCommand.php

示例13: getNormalizedFilename

 /**
  * @param File $file
  * @return string
  */
 protected function getNormalizedFilename(File $file)
 {
     if ($file instanceof UploadedFile) {
         $originalFilename = $file->getClientOriginalName();
         $size = $file->getClientSize();
     } else {
         $originalFilename = $file->getFilename();
         $size = $file->getSize();
     }
     $name = preg_replace(self::REGEX_FILENAME_EXT, '', $originalFilename);
     $name = preg_replace(self::REGEX_INVALID_FILENAME_CHARS, '_', $name);
     $hash = substr(sha1(json_encode(array(time(), $name, $size))), 0, 7);
     $ext = $file->getExtension();
     if (!$ext) {
         $ext = explode('.', $originalFilename);
         $ext = end($ext);
     }
     $filename = sprintf('%s_%s.%s', $name, $hash, $ext);
     return $filename;
 }
开发者ID:Kyoushu,项目名称:CommonBundle,代码行数:24,代码来源:UploadHandler.php

示例14: documentsAction

 public function documentsAction($filename, $originalName = null)
 {
     $documentManager = $this->get('wealthbot_user.document_manager');
     try {
         $file = new File($this->container->getParameter('uploads_documents_dir') . '/' . $filename);
     } catch (FileNotFoundException $e) {
         throw $this->createNotFoundException('File does not exist.');
     }
     if ($file->getExtension() === 'zip') {
         if (null === $originalName) {
             $originalName = $filename;
         }
     } else {
         $document = $documentManager->findDocumentBy(array('filename' => $filename));
         if (!$document) {
             throw $this->createNotFoundException('Document does not exist.');
         }
         if (null === $originalName) {
             $originalName = $document->getOriginalName();
         }
     }
     return $this->prepareResponse($file, $originalName);
 }
开发者ID:junjinZ,项目名称:wealthbot,代码行数:23,代码来源:FilesController.php

示例15: setFile

 /**
  * Set file
  *
  * @param File $file
  * @return $this
  */
 public function setFile(File $file = null)
 {
     $this->file = $file;
     if (is_file($this->getAbsolutePath())) {
         $this->temp = $this->getAbsolutePath();
     }
     if (null !== $file) {
         $extension = $file->getExtension() ? $file->getExtension() : $file->guessExtension();
         if ($file instanceof UploadedFile) {
             $this->setOriginalName($file->getClientOriginalName());
             if (!$extension) {
                 $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
             }
             $filename = sha1($file->getClientOriginalName() . rand(0, 99999)) . '.' . $extension;
             $mimeType = $file->getMimeType();
         } else {
             $this->setOriginalName($file->getFilename());
             $filename = sha1($file->getFilename() . rand(0, 99999)) . '.' . $extension;
             $mimeType = $file->getMimeType();
         }
         $this->setFilename($filename);
         $this->setMimeType($mimeType);
     }
     return $this;
 }
开发者ID:junjinZ,项目名称:wealthbot,代码行数:31,代码来源:Document.php


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