本文整理汇总了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());
}
}
}
示例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;
}
示例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()));
}
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
}
示例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();
}
示例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();
}
示例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);
}
示例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;
}
示例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]);
}
示例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;
}
示例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;
}
示例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');
}