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