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


PHP SplFileInfo::getBasename方法代码示例

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


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

示例1: preUpload

 /**
  * @ORM\PreFlush()
  */
 public function preUpload()
 {
     if ($this->file) {
         if ($this->file instanceof FileUpload) {
             $basename = $this->file->getSanitizedName();
             $basename = $this->suggestName($this->getFilePath(), $basename);
             $this->setName($basename);
         } else {
             $basename = trim(Strings::webalize($this->file->getBasename(), '.', FALSE), '.-');
             $basename = $this->suggestName(dirname($this->file->getPathname()), $basename);
             $this->setName($basename);
         }
         if ($this->_oldPath && $this->_oldPath !== $this->path) {
             @unlink($this->getFilePathBy($this->_oldProtected, $this->_oldPath));
         }
         if ($this->file instanceof FileUpload) {
             $this->file->move($this->getFilePath());
         } else {
             copy($this->file->getPathname(), $this->getFilePath());
         }
         return $this->file = NULL;
     }
     if (($this->_oldPath || $this->_oldProtected !== NULL) && ($this->_oldPath != $this->path || $this->_oldProtected != $this->protected)) {
         $oldFilePath = $this->getFilePathBy($this->_oldProtected !== NULL ? $this->_oldProtected : $this->protected, $this->_oldPath ?: $this->path);
         if (file_exists($oldFilePath)) {
             rename($oldFilePath, $this->getFilePath());
         }
     }
 }
开发者ID:svobodni,项目名称:web,代码行数:32,代码来源:FileEntity.php

示例2: accept

    /**
     * UnsortedEpisodesFilter::accept()
     *
     * @return
     */
    public function accept()
    {
        $file = new SplFileInfo( $this->getInnerIterator()->current() );

        if ( !$file->isFile() )
        {
            echo "Not a file<br />";
            return false;
        }


        if ( !preg_match( '/\.(mkv|avi)$/ ', $file->getBasename() ) )
        {
            echo "Not a video<br />";
            return false;
        }

        if ( $file->getSize() < ( 25 * 1024 * 1024 ) )
        {
            echo "Too small<br />";
            return false;
        }

        $subtitleFileNames = array( $file->getBasename() . '.srt', $file->getBasename() . '.ass' );
        foreach ( $subtitleFileNames as $subtitleFileName )
            if ( file_exists( $subtitleFileName ) )
                return false;
    }
开发者ID:rangulicon,项目名称:mkvmanager,代码行数:33,代码来源:unsorted_episodes.php

示例3: upload

 /**
  * Upload an image to local server then return new image path after upload success
  * 
  * @param array $file [tmp_name, name, error, type, size] 
  * @param string image path for saving (this may constain filename)
  * @param string image filename for saving
  * @return string Image path after uploaded
  * @throws Exception If upload failed
  */
 public function upload($file, $newImagePath = '.', $newImageName = NULL)
 {
     if (!empty($file['error'])) {
         $this->_throwException(':method: Upload error. Number: :number', array(':method' => __METHOD__, ':number' => $file['error']));
     }
     if (getimagesize($file['tmp_name']) === FALSE) {
         $this->_throwException(':method: The file is not an image file.', array(':method' => __METHOD__));
     }
     $fileInfo = new \SplFileInfo($newImagePath);
     if (!$fileInfo->getRealPath() or !$fileInfo->isDir()) {
         $this->_throwException(':method: The ":dir" must be a directory.', array(':method' => __METHOD__, ':dir' => $newImagePath));
     }
     $defaultExtension = '.jpg';
     if (empty($newImageName)) {
         if (!in_array($fileInfo->getBasename(), array('.', '..')) and $fileInfo->getExtension()) {
             $newImageName = $fileInfo->getBasename();
         } else {
             $newImageName = uniqid() . $defaultExtension;
         }
     }
     if (!$fileInfo->isWritable()) {
         $this->_throwException(':method: Directory ":dir" is not writeable.', array(':method' => __METHOD__, ':dir' => $fileInfo->getRealPath()));
     }
     $destination = $fileInfo->getRealPath() . DIRECTORY_SEPARATOR . $newImageName;
     if (move_uploaded_file($file['tmp_name'], $destination)) {
         return $destination;
     } else {
         $this->_throwException(':method: Cannot move uploaded file to :path', array(':method' => __METHOD__, ':path' => $fileInfo->getRealPath()));
     }
 }
开发者ID:0hyeah,项目名称:yurivn,代码行数:39,代码来源:Local.php

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

示例5: load

 /**
  * Load all extension classes
  */
 public function load()
 {
     $counter = 0;
     foreach (glob(__DIR__ . '/Extension/*.php') as $filename) {
         $file = new \SplFileInfo($filename);
         $classname = $file->getBasename('.php');
         $classpath = sprintf('%s\\Extension\\%s', __NAMESPACE__, $classname);
         require_once $filename;
         $extension = new \ReflectionClass($classpath);
         $instance = $extension->newInstance($this->getParent());
         foreach ($extension->getMethods() as $method) {
             if (mb_substr($method->name, 0, 3) == 'FN_') {
                 $map = new \StdClass();
                 $map->class = $extension->getShortName();
                 $map->method = $method->name;
                 $map->instance = $instance;
                 $tag = sprintf('%s.%s', mb_strtolower($classname), mb_substr($method->name, 3));
                 $this->mapping[$tag] = $map;
             }
         }
         $this->debug(__METHOD__, __LINE__, sprintf('Loaded extension: %s', $extension->getShortName()));
         // save the instance
         $this->instances[] = $instance;
         $counter++;
     }
     return $counter;
 }
开发者ID:g4z,项目名称:poop,代码行数:30,代码来源:ExtensionManager.php

示例6: getBasename

 /**
  * Returns base name of file without extension (or base name of directory).
  *
  * @param string $suffix
  *
  * @return string
  */
 public function getBasename($suffix = null)
 {
     if (null === $suffix) {
         $suffix = static::SEPARATOR_EXTENSION . $this->getExtension();
     }
     return parent::getBasename((string) $suffix);
 }
开发者ID:zk2,项目名称:FileNamingResolver,代码行数:14,代码来源:FileInfo.php

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

示例8:

 function __construct(\SplFileInfo $file, $contentType, $filename = null, $fileExtension = null)
 {
     $this->file = $file;
     $this->filename = $filename ?: $file->getBasename();
     $this->contentType = $contentType;
     $this->fileExtension = $fileExtension ?: $file->getExtension();
 }
开发者ID:cwd,项目名称:TableBundle,代码行数:7,代码来源:Export.php

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

示例10: __construct

 /**
  * @param \SplFileInfo $fileInfo
  * @param string       $downloadDirUrl
  */
 public function __construct(\SplFileInfo $fileInfo, $downloadDirUrl)
 {
     $this->size = $fileInfo->getSize();
     $this->fileName = $fileInfo->getBasename();
     $this->lastModified = \DateTime::createFromFormat("U", $fileInfo->getMTime());
     $this->url = "{$downloadDirUrl}/" . rawurlencode($this->fileName);
 }
开发者ID:becklyn,项目名称:gluggi,代码行数:11,代码来源:Download.php

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

示例12: fileUploadFromFile

 /**
  * @param string $filename
  * @return FileUpload
  */
 public static function fileUploadFromFile($filename)
 {
     if (!file_exists($filename)) {
         throw new FileNotExistsException("File '{$filename}' does not exists");
     }
     $file = new \SplFileInfo($filename);
     return new FileUpload(['name' => $file->getBasename(), 'type' => $file->getType(), 'size' => $file->getSize(), 'tmp_name' => $filename, 'error' => 0]);
 }
开发者ID:ondrs,项目名称:upload-manager,代码行数:12,代码来源:Utils.php

示例13: buildElephantFile

 public function buildElephantFile($file)
 {
     $file = new \SplFileInfo($file);
     $resultFile = $file->getPath() . DIRECTORY_SEPARATOR . $file->getBasename('.elph') . '.php';
     $rewriter = new Rewriter($resultFile);
     $rewriter->save();
     return $resultFile;
 }
开发者ID:rodchyn,项目名称:elephant-lang,代码行数:8,代码来源:Autoload.php

示例14: __construct

 /**
  * Class constructor
  *
  * @param  string  $file_name  File name
  */
 public function __construct($file_name)
 {
     // Construct a new SplFileInfo object
     $spl = new SplFileInfo($file_name);
     $this->_name = $spl->getBasename();
     $this->_path = $spl->getPath();
     self::$instance = $this;
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:13,代码来源:file.php

示例15: let

 function let(\SplFileInfo $file, Suite $suite)
 {
     $file->getFilename()->willReturn(__FILE__);
     $file->getPath()->willReturn(__DIR__);
     $file->getBasename('.php')->willReturn('SpecSpec');
     $this->beConstructedWith($file, $suite, realpath(__DIR__ . '/../../../../..'));
     $this->shouldHaveType('Funk\\Specification\\Locator\\Iterator\\Spec');
 }
开发者ID:docteurklein,项目名称:funk-spec,代码行数:8,代码来源:SpecSpec.php


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