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


PHP SplFileInfo::getExtension方法代码示例

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


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

示例1: __construct

 /**
  * Class init.
  *
  * @param string $path
  * @param string $root
  */
 public function __construct($path, $root)
 {
     $this->root = $root;
     $this->path = ltrim(str_replace(realpath($root), '', realpath($path)), '/\\');
     $this->fileInfo = new \SplFileInfo($root . '/' . $path);
     $this->name = File::stripExtension($this->fileInfo->getBasename());
     $this->type = $this->fileInfo->getExtension();
 }
开发者ID:bgao-ca,项目名称:vaseman,代码行数:14,代码来源:Asset.php

示例2: getFileDetailsRaw

 /**
  * Returns the details about Communicator (current) file
  * w/o any kind of verification of file existance
  *
  * @param string $fileGiven
  * @return array
  */
 protected function getFileDetailsRaw($fileGiven)
 {
     $info = new \SplFileInfo($fileGiven);
     $aFileBasicDetails = ['File Extension' => $info->getExtension(), 'File Group' => $info->getGroup(), 'File Inode' => $info->getInode(), 'File Link Target' => $info->isLink() ? $info->getLinkTarget() : '-', 'File Name' => $info->getBasename('.' . $info->getExtension()), 'File Name w. Extension' => $info->getFilename(), 'File Owner' => $info->getOwner(), 'File Path' => $info->getPath(), 'Name' => $info->getRealPath(), 'Type' => $info->getType()];
     $aDetails = array_merge($aFileBasicDetails, $this->getFileDetailsRawStatistic($info, $fileGiven));
     ksort($aDetails);
     return $aDetails;
 }
开发者ID:danielgp,项目名称:common-lib,代码行数:15,代码来源:CommonBasic.php

示例3: run

 /**
  * Interpolates a string by substituting tokens in a string
  * 
  * Default interpolations:
  * - `:webroot` Path to the webroot folder
  * - `:model` The current model e.g images
  * - `:field` The database field
  * - `:filename` The filename
  * - `:extension` The extension of the file e.g png
  * - `:id` The record id
  * - `:style` The current style e.g thumb
  * - `:hash` Generates a hash based on the filename
  * 
  * @param string $string The string to be interpolated with data.
  * @param string $name The name of the model e.g. Image
  * @param int $id The id of the record e.g 1
  * @param string $field The name of the database field e.g file
  * @param string $style The style to use. Should be specified in the behavior settings.
  * @param array $options You can override the default interpolations by passing an array of key/value
  *              pairs or add extra interpolations. For example, if you wanted to change the hash method
  *              you could pass `array('hash' => sha1($id . Configure::read('Security.salt')))`
  * @return array Settings array containing interpolated strings along with the other settings for the field.
  */
 public static function run($string, $name, $id, $field, $filename, $style = 'original', $data = array())
 {
     $info = new SplFileInfo($filename);
     $data += array('webroot' => preg_replace('/\\/$/', '', WWW_ROOT), 'model' => Inflector::tableize($name), 'field' => strtolower($field), 'filename' => $info->getBasename($info->getExtension()), 'extension' => $info->getExtension(), 'id' => $id, 'style' => $style, 'hash' => md5($info->getFilename() . Configure::read('Security.salt')));
     foreach (static::$_interpolations as $name => $closure) {
         $data[$name] = $closure($info);
     }
     return String::insert($string, $data);
 }
开发者ID:rickydunlop,项目名称:Uploader,代码行数:32,代码来源:Interpolation.php

示例4: load

 /**
  *
  * @param string $filename
  *
  * @return \CSanquer\FakeryGenerator\Model\Config
  *
  * @throws \InvalidArgumentException
  */
 public function load($filename)
 {
     $file = new \SplFileInfo($filename);
     if (!in_array($file->getExtension(), ['json', 'xml'])) {
         throw new \InvalidArgumentException('The config file must be an XML or a JSON file.');
     }
     if (!file_exists($file->getRealPath())) {
         throw new \InvalidArgumentException('The config file must exist.');
     }
     return $this->serializer->deserialize(file_get_contents($file->getRealPath()), 'CSanquer\\FakeryGenerator\\Model\\Config', $file->getExtension());
 }
开发者ID:csanquer,项目名称:fakery-generator,代码行数:19,代码来源:ConfigSerializer.php

示例5: getFileExtension

 /**
  * @param \SplFileInfo $fileInfo
  * @return mixed|string
  */
 private function getFileExtension(\SplFileInfo $fileInfo)
 {
     if ($fileInfo instanceof UploadedFile) {
         return pathinfo($fileInfo->getClientOriginalName(), PATHINFO_EXTENSION);
     }
     return $fileInfo->getExtension();
 }
开发者ID:da-vinci-studio,项目名称:file-bundle,代码行数:11,代码来源:FileReceiver.php

示例6: __invoke

 /**
  * Performs a check of file
  *
  * @param \SplFileInfo $file File to check
  *
  * @return bool
  */
 public function __invoke(\SplFileInfo $file)
 {
     $rootDirectory = $this->rootDirectory;
     $includePaths = $this->includePaths;
     $excludePaths = $this->excludePaths;
     if ($file->getExtension() !== 'php') {
         return false;
     }
     $realPath = $file->getRealPath();
     // Do not touch files that not under rootDirectory
     if (strpos($realPath, $rootDirectory) !== 0) {
         return false;
     }
     if ($includePaths) {
         $found = false;
         foreach ($includePaths as $includePath) {
             if (strpos($realPath, $includePath) === 0) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             return false;
         }
     }
     foreach ($excludePaths as $excludePath) {
         if (strpos($realPath, $excludePath) === 0) {
             return false;
         }
     }
     return true;
 }
开发者ID:goaop,项目名称:ast-manipulator,代码行数:39,代码来源:FileFilter.php

示例7: crop

 public function crop()
 {
     $input = Input::all();
     $quality = 90;
     $sizes = $this->getSizes($input['ratio']);
     $sourceImage = $this->uploadsDirectory . $input['directory'] . '/' . $input['image'];
     $fileInfo = new \SplFileInfo($sourceImage);
     $fileExtension = $fileInfo->getExtension();
     foreach ($sizes as $sizeKey => $size) {
         $croppedImageName = preg_replace('/^(.*)\\.' . $fileExtension . '$/', '$1_' . $sizeKey . '.' . $fileExtension, $input['image']);
         $croppedImageFullPath = $this->uploadsDirectory . $input['directory'] . '/' . $croppedImageName;
         if ($fileExtension === 'jpg' || $fileExtension === 'jpeg') {
             $jpgImage = imagecreatefromjpeg($sourceImage);
             $jpgTempImage = imagecreatetruecolor($size[0], $size[1]);
             imagecopyresampled($jpgTempImage, $jpgImage, 0, 0, $input['x'], $input['y'], $size[0], $size[1], $input['w'], $input['h']);
             imagejpeg($jpgTempImage, $croppedImageFullPath, $quality);
         } else {
             if ($fileExtension === 'png') {
                 $pngImage = imagecreatefrompng($sourceImage);
                 $pngTempImage = imagecreatetruecolor($size[0], $size[1]);
                 imagecopyresampled($pngTempImage, $pngImage, 0, 0, $input['x'], $input['y'], $size[0], $size[1], $input['w'], $input['h']);
                 imagepng($pngTempImage, $croppedImageFullPath, round((100 - $quality) * 0.09));
             }
         }
     }
     $previewSize = isset($input['preview_size']) ? $input['preview_size'] : 't';
     $imageUrl = asset('images/uploads' . $input['directory'] . '/' . ImageHelper::getImage($input['image'], $previewSize));
     return redirect()->route('image_done', ['target' => $input['target'], 'id' => $input['id'], 'directory' => base64_encode($input['directory']), 'image' => base64_encode($input['image']), 'url' => base64_encode($imageUrl)]);
 }
开发者ID:noonic,项目名称:laravel-base-image,代码行数:29,代码来源:ImagesController.php

示例8: uploadFromurl

 /**
  *
  */
 public function uploadFromurl($url = null)
 {
     $uploadOk = 1;
     $opts = array('http' => array('method' => 'GET', 'max_redirects' => '0', 'ignore_errors' => '1'));
     $context = stream_context_create($opts);
     $info = new SplFileInfo($url);
     if (strtolower($info->getExtension()) != "jpg") {
         $uploadOk = 0;
         $this->error = "Only JPG";
     } else {
         $imageFileType = "jpg";
     }
     if ($uploadOk) {
         $result = file_get_contents($url, false, $context);
         if ($result) {
             //   $temp = tempnam(sys_get_temp_dir(), 'TMP_');
             //  $imageFileType = pathinfo($temp, PATHINFO_EXTENSION);
             $new_file = $this->getFilename($imageFileType);
             $new_file_th = $this->getFilenameth($imageFileType);
             if (file_exists($new_file)) {
                 unlink($new_file);
             }
             if (file_exists($new_file_th)) {
                 unlink($new_file_th);
             }
             file_put_contents($new_file, $result);
             $this->greateTH($new_file, $new_file_th);
             return true;
         } else {
             $this->error = "Невозможно скачать файл";
         }
     }
 }
开发者ID:pumi11,项目名称:veselkina,代码行数:36,代码来源:PostFile.class.php

示例9: resolve

 /**
  * @param \SplFileInfo $file
  *
  * @return NodeParserInterface|null
  */
 public function resolve(\SplFileInfo $file)
 {
     if ('php' === strtolower($file->getExtension())) {
         return $this->getPhpClassExtractor();
     }
     return null;
 }
开发者ID:akeneo,项目名称:php-coupling-detector,代码行数:12,代码来源:NodeParserResolver.php

示例10: deployProcess

 public function deployProcess(\SplFileInfo $file, $name = NULL)
 {
     $builder = new DeploymentBuilder($name === NULL ? $file->getFilename() : $name);
     $builder->addExtensions($file->getExtension());
     $builder->addResource($file->getFilename(), $file);
     return $this->deploy($builder);
 }
开发者ID:Lesspion,项目名称:bpmn,代码行数:7,代码来源:RepositoryService.php

示例11: loadConfig

 /**
  * Load config data. Support php|ini|yml config formats.
  *
  * @param string|\SplFileInfo $configFile
  * @throws ConfigException
  */
 public function loadConfig($configFile)
 {
     if (!$configFile instanceof \SplFileInfo) {
         if (!is_string($configFile)) {
             throw new ConfigException('Mismatch type of variable.');
         }
         $path = realpath($this->basePath . $configFile);
         // check basePath at mutation
         if (strpos($configFile, '..') || !strpos($path, realpath($this->basePath))) {
             throw new ConfigException('Config file name: ' . $configFile . ' isn\'t correct.');
         }
         if (!is_file($path) || !is_readable($path)) {
             throw new ConfigException('Config file: ' . $path . ' not found of file isn\'t readable.');
         }
         $configFile = new \SplFileInfo($path);
     }
     $path = $configFile->getRealPath();
     $ext = $configFile->getExtension();
     $key = $configFile->getBasename('.' . $ext);
     if ('php' === $ext) {
         $this->data[$key] = (include $path);
     } elseif ('ini' === $ext) {
         $this->data[$key] = parse_ini_file($path, true);
     } elseif ('yml' === $ext) {
         if (!function_exists('yaml_parse_file')) {
             throw new ConfigException("Function `yaml_parse_file` isn't supported.\n" . 'http://php.net/manual/en/yaml.requirements.php');
         }
         $this->data[$key] = yaml_parse_file($path);
     }
 }
开发者ID:qwant50,项目名称:config,代码行数:36,代码来源:Config.php

示例12: getCustomWidgets

 function getCustomWidgets($dir)
 {
     $customwidgets = array();
     $widgetdir = get_option('widgetdir');
     if (file_exists($dir)) {
         $cdir = scandir($dir);
     } else {
         return;
     }
     foreach ($cdir as $d) {
         if ($d == "." || $d == ".." || $d == ".svn") {
             continue;
         }
         if (is_dir($widgetdir . '/' . $d) == TRUE) {
             $dirFile = scandir($widgetdir . '/' . $d);
             foreach ($dirFile as $dir) {
                 $info = new SplFileInfo($dir);
                 if (is_dir($dir) == FALSE && $info->getExtension() == 'php') {
                     $file = $d . '/' . $dir;
                     array_push($customwidgets, $file);
                 }
             }
         } else {
             if (is_dir($d) == FALSE) {
                 array_push($customwidgets, $d);
             }
         }
     }
     return $customwidgets;
 }
开发者ID:JasonDarkX2,项目名称:Wordpress-WidgetManager,代码行数:30,代码来源:theWidget.php

示例13: src

 public function src($src, $ext = null)
 {
     if (!is_file($src)) {
         throw new FileNotFoundException($src);
     }
     $this->src = $src;
     if (!$ext) {
         $info = new \SplFileInfo($src);
         $this->ext = strtoupper($info->getExtension());
     } else {
         $this->ext = strtoupper($ext);
     }
     if (is_file($src) && ($this->ext == "JPG" or $this->ext == "JPEG")) {
         $this->image = ImageCreateFromJPEG($src);
     } else {
         if (is_file($src) && $this->ext == "PNG") {
             $this->image = ImageCreateFromPNG($src);
         } else {
             throw new FileNotFoundException($src);
         }
     }
     $this->input_width = imagesx($this->image);
     $this->input_height = imagesy($this->image);
     return $this;
 }
开发者ID:jilson-asis,项目名称:image-resize,代码行数:25,代码来源:ImageResizer.php

示例14: postSave

 /**
  * todo - добавить проверки и исключения
  * todo - вывести пути в конфиги
  *
  * @param $result
  * @throws \Exception
  */
 protected function postSave($result)
 {
     if (is_array($result)) {
         $data = $this->getData();
         $id = $data['id'];
     } elseif ($result) {
         $id = (int) $result;
     } else {
         $id = 0;
     }
     if (!empty($_FILES['file']['name']) && $id) {
         $configTwigUpload = App::getInstance()->getConfigParam('upload_files');
         if (!isset($configTwigUpload['images_category_and_product'])) {
             throw new \Exception('Неверные Параметры конфигурации upload_files');
         }
         $prefix = $configTwigUpload['images_category_and_product'] . '/category/';
         $uploaddir = App::getInstance()->getCurrDir() . '/web' . $prefix;
         $info = new \SplFileInfo($_FILES['file']['name']);
         $fileExtension = $info->getExtension();
         $uploadfile = $uploaddir . $id . '.' . $fileExtension;
         $uploadfileDB = $prefix . $id . '.' . $fileExtension;
         if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
             $tbl = $this->getDataClass();
             $tbl->update(array('file' => $uploadfileDB), array('id' => $id));
         } else {
             throw new \Exception('Ошибка при сохранении изображения');
         }
     }
 }
开发者ID:prishlyakvv,项目名称:guitar,代码行数:36,代码来源:CategoryFormType.php

示例15: extractZipArchive

 /**
  * Extract the zip archive to be imported
  *
  * @throws \RuntimeException When archive cannot be opened or extracted or does not contain exactly one file file
  */
 protected function extractZipArchive()
 {
     $archive = new \ZipArchive();
     $status = $archive->open($this->filePath);
     if (true !== $status) {
         throw new \RuntimeException(sprintf('Error "%d" occurred while opening the zip archive.', $status));
     }
     $path = $this->fileInfo->getPath();
     $filename = $this->fileInfo->getBasename('.' . $this->fileInfo->getExtension());
     $targetDir = sprintf('%s/%s', $path, $filename);
     if (!$archive->extractTo($targetDir)) {
         throw new \RuntimeException('Error occurred while extracting the zip archive.');
     }
     $archive->close();
     $this->archivePath = $targetDir;
     $finder = new Finder();
     $files = $finder->in($targetDir)->name('/\\.' . $this->type . '$/i');
     $count = $files->count();
     if (1 !== $count) {
         throw new \RuntimeException(sprintf('Expecting the root directory of the archive to contain exactly 1 file file, found %d', $count));
     }
     $filesIterator = $files->getIterator();
     $filesIterator->rewind();
     $this->filePath = $filesIterator->current()->getPathname();
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:30,代码来源:FlatFileIterator.php


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