本文整理汇总了PHP中TYPO3\CMS\Core\Utility\PathUtility::dirname方法的典型用法代码示例。如果您正苦于以下问题:PHP PathUtility::dirname方法的具体用法?PHP PathUtility::dirname怎么用?PHP PathUtility::dirname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Utility\PathUtility
的用法示例。
在下文中一共展示了PathUtility::dirname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRelativePath
/**
* Return a public path pointing to a resource.
*
* @param string $resource
* @return string
*/
public static function getRelativePath($resource)
{
// If file is not found, resolve the path
if (!is_file(PATH_site . $resource)) {
$resource = substr(self::resolvePath($resource), strlen(PATH_site));
}
return PathUtility::getRelativePathTo(PathUtility::dirname(PATH_site . $resource)) . PathUtility::basename($resource);
}
示例2: getUrl
/**
* Get url
*
* @param bool $relativeToCurrentScript Determines whether the URL returned should be relative to the current script, in case it is relative at all.
* @return string
*/
public function getUrl($relativeToCurrentScript = false)
{
$url = $this->url;
if ($relativeToCurrentScript && !GeneralUtility::isValidUrl($url)) {
$absolutePathToContainingFolder = PathUtility::dirname(PATH_site . $url);
$pathPart = PathUtility::getRelativePathTo($absolutePathToContainingFolder);
$filePart = substr(PATH_site . $url, strlen($absolutePathToContainingFolder) + 1);
$url = $pathPart . $filePart;
}
return $url;
}
示例3: writeFileAndCreateFolder
/**
* Write a file and create the target folder, if the folder do not exists
*
* @param string $absoluteFileName
* @param string $content
*
* @return bool
* @throws Exception
*/
public static function writeFileAndCreateFolder($absoluteFileName, $content)
{
$dir = PathUtility::dirname($absoluteFileName) . '/';
if (!is_dir($dir)) {
GeneralUtility::mkdir_deep($dir);
}
if (is_file($absoluteFileName) && !is_writable($absoluteFileName)) {
throw new Exception('The autoloader try to add same content to ' . $absoluteFileName . ' but the file is not writable for the autoloader. Please fix it!', 234627835);
}
return GeneralUtility::writeFile($absoluteFileName, $content);
}
示例4: getVirtualFileObject
/**
* Creates a virtual File object to be used transparently by external
* metadata extraction services as if it would come from standard FAL.
*
* @param string $fileName
* @param array $metadata
* @return \TYPO3\CMS\Core\Resource\File
*/
protected static function getVirtualFileObject($fileName, array $metadata)
{
/** @var \TYPO3\CMS\Core\Resource\ResourceFactory $resourceFactory */
$resourceFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceFactory::class);
$recordData = ['uid' => 0, 'pid' => 0, 'name' => 'Temporary Upload Storage', 'description' => 'Internal storage, mounting the temporary PHP upload directory.', 'driver' => 'Local', 'processingfolder' => '', 'configuration' => '', 'is_online' => true, 'is_browsable' => false, 'is_public' => false, 'is_writable' => false, 'is_default' => false];
$storageConfiguration = ['basePath' => PathUtility::dirname($fileName), 'pathType' => 'absolute'];
$virtualStorage = $resourceFactory->createStorageObject($recordData, $storageConfiguration);
$name = PathUtility::basename($fileName);
$extension = strtolower(substr($name, strrpos($name, '.') + 1));
/** @var \TYPO3\CMS\Core\Resource\File $virtualFileObject */
$virtualFileObject = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\File::class, ['identifier' => '/' . $name, 'name' => $name, 'extension' => $extension], $virtualStorage, $metadata);
return $virtualFileObject;
}
示例5: getExistingFiles
/**
* Handles the existing files of a Fine Uploader form.
* The values are stored in the GET/POST var at the index "fieldValue".
*
* @return string
*/
public function getExistingFiles()
{
$files = array();
$fieldValue = GeneralUtility::_GP('fieldValue');
if ($fieldValue != '') {
$imagePath = GeneralUtility::getFileAbsFileName($fieldValue);
$imageName = PathUtility::basename($imagePath);
$imageDirectoryPath = PathUtility::dirname($imagePath);
$imageDirectoryPath = PathUtility::getRelativePath(PATH_site, $imageDirectoryPath);
$imageUrl = GeneralUtility::locationHeaderUrl('/' . $imageDirectoryPath . $imageName);
if (file_exists($imagePath)) {
$files[] = array('name' => $imageName, 'uuid' => $imageUrl, 'thumbnailUrl' => $imageUrl);
}
}
return json_encode($files);
}
示例6: getExistingFiles
/**
* Handles the existing files of a Fine Uploader form.
* The values are stored in the GET/POST var at the index "fieldValue".
*
* @return string
*/
public function getExistingFiles()
{
$files = [];
$fieldValue = GeneralUtility::_GP('fieldValue');
if ($fieldValue != '') {
// $imagePath = GeneralUtility::getFileAbsFileName($fieldValue);
$imagePath = str_replace('new:', '', $fieldValue);
$imageName = PathUtility::basename($imagePath);
$imageDirectoryPath = PathUtility::dirname($imagePath);
$imageDirectoryPath = PathUtility::getRelativePath(PATH_site, $imageDirectoryPath);
$imageUrl = GeneralUtility::locationHeaderUrl('/' . $imageDirectoryPath . $imageName);
if (file_exists($imagePath)) {
$files[] = ['name' => $imageName, 'uuid' => $imageUrl, 'thumbnailUrl' => $imageUrl];
}
}
return $files;
}
示例7: getPublicUrl
/**
* @param ResourceStorage $storage
* @param AbstractDriver $driver
* @param ResourceInterface $resource
* @param boolean $relativeToCurrentScript
* @param array $urlData
*/
public function getPublicUrl(ResourceStorage $storage, AbstractDriver $driver, ResourceInterface $resource, $relativeToCurrentScript, array $urlData)
{
if (!$driver instanceof LocalDriver) {
// We cannot handle other files than local files yet
return;
}
$publicUrl = $this->resourcePublisher->getResourceWebUri($resource);
if ($publicUrl !== FALSE) {
// If requested, make the path relative to the current script in order to make it possible
// to use the relative file
if ($relativeToCurrentScript) {
$publicUrl = PathUtility::getRelativePathTo(PathUtility::dirname(PATH_site . $publicUrl)) . PathUtility::basename($publicUrl);
}
// $urlData['publicUrl'] is passed by reference, so we can change that here and the value will be taken into account
$urlData['publicUrl'] = $publicUrl;
}
}
示例8: checkCshFile
/**
* Check if the given file is already existing
*
* @param $path
* @param $modelClass
*
* @return void
*/
protected function checkCshFile($path, $modelClass)
{
if (is_file($path)) {
return;
}
$dir = PathUtility::dirname($path);
if (!is_dir($dir)) {
GeneralUtility::mkdir_deep($dir);
}
$information = SmartObjectInformationService::getInstance()->getCustomModelFieldTca($modelClass);
$properties = array_keys($information);
$templatePath = 'Resources/Private/Templates/ContextSensitiveHelp/LanguageDescription.xml';
$standaloneView = GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
$standaloneView->setTemplatePathAndFilename(ExtensionManagementUtility::extPath('autoloader', $templatePath));
$standaloneView->assign('properties', $properties);
$content = $standaloneView->render();
FileUtility::writeFileAndCreateFolder($path, $content);
}
示例9: renameFolder
/**
* Renames a folder in this storage.
*
* @param string $folderIdentifier
* @param string $newName
* @return array A map of old to new file identifiers of all affected files and folders
* @throws \RuntimeException if renaming the folder failed
*/
public function renameFolder($folderIdentifier, $newName)
{
$folderIdentifier = $this->canonicalizeAndCheckFolderIdentifier($folderIdentifier);
$newName = $this->sanitizeFileName($newName);
$newIdentifier = PathUtility::dirname($folderIdentifier) . '/' . $newName;
$newIdentifier = $this->canonicalizeAndCheckFolderIdentifier($newIdentifier);
$sourcePath = $this->getAbsolutePath($folderIdentifier);
$targetPath = $this->getAbsolutePath($newIdentifier);
// get all files and folders we are going to move, to have a map for updating later.
$filesAndFolders = $this->retrieveFileAndFoldersInPath($sourcePath, true);
$result = rename($sourcePath, $targetPath);
if ($result === false) {
throw new \RuntimeException(sprintf('Renaming folder "%1$s" to "%2$s" failed."', $sourcePath, $targetPath), 1320375116);
}
try {
// Create a mapping from old to new identifiers
$identifierMap = $this->createIdentifierMap($filesAndFolders, $folderIdentifier, $newIdentifier);
} catch (\Exception $e) {
rename($targetPath, $sourcePath);
throw new \RuntimeException(sprintf('Creating filename mapping after renaming "%1$s" to "%2$s" failed. Reverted rename operation.\\n\\nOriginal error: %3$s"', $sourcePath, $targetPath, $e->getMessage()), 1334160746);
}
return $identifierMap;
}
示例10: getFileInfoByIdentifier
/**
* Returns information about a file.
*
* @param string $fileIdentifier
* @param array $propertiesToExtract Array of properties which are be extracted
* If empty all will be extracted
* @return array
* @throws FileDoesNotExistException
*/
public function getFileInfoByIdentifier($fileIdentifier, array $propertiesToExtract = [])
{
$relativeDriverPath = ltrim($fileIdentifier, '/');
if (!$this->filesystem->has($relativeDriverPath) || !$this->filesystem->get($relativeDriverPath)->isFile()) {
throw new FileDoesNotExistException('File ' . $fileIdentifier . ' does not exist.', 1314516809);
}
$dirPath = PathUtility::dirname($fileIdentifier);
$dirPath = $this->canonicalizeAndCheckFolderIdentifier($dirPath);
return $this->extractFileInformation($relativeDriverPath, $dirPath, $propertiesToExtract);
}
示例11: writeSysFileResourceForLegacyImport
/**
* Writes the file with the is $fileId to the legacy import folder. The file name will used from
* argument $fileName and the file was successfully created or an identical file was already found,
* $fileName will held the uid of the new created file record.
*
* @param string $fileName The file name for the new file. Value would be changed to the uid of the new created file record.
* @param int $fileId The id of the file in data array
* @return bool
*/
protected function writeSysFileResourceForLegacyImport(&$fileName, $fileId)
{
if ($this->legacyImportFolder === null) {
return false;
}
if (!isset($this->dat['files'][$fileId])) {
$this->error('ERROR: File ID "' . $fileId . '" could not be found');
return false;
}
$temporaryFile = $this->writeTemporaryFileFromData($fileId, 'files');
if ($temporaryFile === null) {
// error on writing the file. Error message was already added
return false;
}
$importFolder = $this->legacyImportFolder;
if (isset($this->dat['files'][$fileId]['relFileName'])) {
$relativeFilePath = PathUtility::dirname($this->dat['files'][$fileId]['relFileName']);
if (!$this->legacyImportFolder->hasFolder($relativeFilePath)) {
$this->legacyImportFolder->createFolder($relativeFilePath);
}
$importFolder = $this->legacyImportFolder->getSubfolder($relativeFilePath);
}
$fileObject = null;
try {
// check, if there is alreay the same file in the folder
if ($importFolder->hasFile($fileName)) {
$fileStorage = $importFolder->getStorage();
$file = $fileStorage->getFile($importFolder->getIdentifier() . $fileName);
if ($file->getSha1() === sha1_file($temporaryFile)) {
$fileObject = $file;
}
}
} catch (Exception $e) {
}
if ($fileObject === null) {
try {
$fileObject = $importFolder->addFile($temporaryFile, $fileName, DuplicationBehavior::RENAME);
} catch (Exception $e) {
$this->error('Error: no file could be added to the storage for file name ' . $this->alternativeFileName[$temporaryFile]);
}
}
if (md5_file(PATH_site . $fileObject->getPublicUrl()) == $this->dat['files'][$fileId]['content_md5']) {
$fileName = $fileObject->getUid();
$this->fileIDMap[$fileId] = $fileName;
$this->filePathMap[$fileId] = $fileObject->getPublicUrl();
return true;
} else {
$this->error('ERROR: File content "' . $this->dat['files'][$fileId]['relFileName'] . '" was corrupted');
}
return false;
}
示例12: processFile
/**
* Processes upload of a file.
*
* @param string $fileName Full path to the file to be processed
* @param string $targetFileName Expected target file name, if not converted (only file name, no path)
* @param string $targetDirectory
* @param \TYPO3\CMS\Core\Resource\File $file
* @param \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUser
* @param callback $callbackNotification Callback to send notification
* @return string File name that was finally written
*/
public function processFile($fileName, $targetFileName = '', $targetDirectory = '', \TYPO3\CMS\Core\Resource\File $file = null, \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUser = null, $callbackNotification = null)
{
$this->lastMetadata = null;
if (!(empty($targetFileName) && empty($targetDirectory))) {
$targetDirectory = rtrim($targetDirectory, '/') . '/';
$ruleset = $this->getRuleset($fileName, $targetDirectory . $targetFileName, $backendUser);
} else {
$ruleset = $this->getRuleset($fileName, $fileName, $backendUser);
}
if (count($ruleset) === 0) {
// File does not match any rule set
return $fileName;
}
$processedFileName = $this->getProcessedFileName($fileName, $backendUser, $ruleset);
if ($processedFileName === null) {
// No processing to do
return $fileName;
}
// Make file name relative, store as $targetFileName
if (empty($targetFileName)) {
$targetFileName = PathUtility::stripPathSitePrefix($fileName);
}
// Extract the extension
if (($dotPosition = strrpos($fileName, '.')) === false) {
// File has no extension
return $fileName;
}
$fileExtension = strtolower(substr($fileName, $dotPosition + 1));
if ($fileExtension === 'png' && !$ruleset['resize_png_with_alpha']) {
if (ImageUtility::isTransparentPng($fileName)) {
$message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:image_autoresize/Resources/Private/Language/locallang.xml:message.imageTransparent'), $targetFileName);
$this->notify($callbackNotification, $message, \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
return $fileName;
}
}
if (!is_writable($fileName)) {
$message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:image_autoresize/Resources/Private/Language/locallang.xml:message.imageNotWritable'), $targetFileName);
$this->notify($callbackNotification, $message, \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
return $fileName;
}
$targetDestFileName = $fileName;
if (isset($ruleset['conversion_mapping'][$fileExtension])) {
// File format will be converted
$destExtension = $ruleset['conversion_mapping'][$fileExtension];
$destDirectory = PathUtility::dirname($fileName);
$destFileName = PathUtility::basename(substr($fileName, 0, strlen($fileName) - strlen($fileExtension)) . $destExtension);
if (empty($targetDirectory)) {
// Ensures $destFileName does not yet exist, otherwise make it unique!
/* @var $fileFunc \TYPO3\CMS\Core\Utility\File\BasicFileUtility */
$fileFunc = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Utility\File\BasicFileUtility::class);
$destFileName = $fileFunc->getUniqueName($destFileName, $destDirectory);
$targetDestFileName = $destFileName;
} else {
$destFileName = $destDirectory . '/' . $destFileName;
$targetDestFileName = $targetDirectory . PathUtility::basename(substr($targetFileName, 0, strlen($targetFileName) - strlen($fileExtension)) . $destExtension);
}
} else {
// File format stays the same
$destExtension = $fileExtension;
$destFileName = $fileName;
}
// Image is bigger than allowed, will now resize it to (hopefully) make it lighter
/** @var $gifCreator \TYPO3\CMS\Frontend\Imaging\GifBuilder */
$gifCreator = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class);
$gifCreator->init();
$gifCreator->absPrefix = PATH_site;
$imParams = $ruleset['keep_metadata'] === '1' ? '###SkipStripProfile###' : '';
$metadata = ImageUtility::getMetadata($fileName, true);
$this->lastMetadata = $metadata;
$isRotated = false;
if ($ruleset['auto_orient'] === '1') {
$orientation = ImageUtility::getOrientation($fileName);
$isRotated = ImageUtility::isRotated($orientation);
$transformation = ImageUtility::getTransformation($orientation);
if ($transformation !== '') {
$imParams .= ' ' . $transformation;
}
}
if ($isRotated) {
// Invert max_width and max_height as the picture
// will be automatically rotated
$options = array('maxW' => $ruleset['max_height'], 'maxH' => $ruleset['max_width']);
} else {
$options = array('maxW' => $ruleset['max_width'], 'maxH' => $ruleset['max_height']);
}
$originalFileSize = filesize($fileName);
$tempFileInfo = null;
$tempFileInfo = $gifCreator->imageMagickConvert($fileName, $destExtension, '', '', $imParams, '', $options, true);
if (filesize($tempFileInfo[3]) >= $originalFileSize - 10240 && $destExtension === $fileExtension) {
//.........这里部分代码省略.........
示例13: filterItems
/**
* @param array $items
* @param array $filterCallbacks
* @return array
*/
protected function filterItems(array $items, array $filterCallbacks)
{
foreach ($items as $identifier => $info) {
foreach ($filterCallbacks as $filterCallback) {
if (is_callable($filterCallback)) {
$result = call_user_func($filterCallback, $info['name'], $identifier, PathUtility::dirname($identifier), [], $this);
if ($result === -1) {
unset($items[$identifier]);
break;
} elseif ($result === false) {
throw new \RuntimeException('Could not apply file/folder name filter ' . $filterCallback[0] . '::' . $filterCallback[1], 1447600899);
}
}
}
}
return $items;
}
示例14: getPublicUrl
/**
* Returns the public URL to a file.
*
* @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource
* @param bool $relativeToCurrentScript Determines whether the URL returned should be relative to the current script, in case it is relative at all (only for the LocalDriver)
* @return string
*/
public function getPublicUrl(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, $relativeToCurrentScript = false)
{
if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($resource->getIdentifier(), '/_processed_/')) {
$publicUrl = '../typo3temp/yag' . $resource->getIdentifier();
// TODO: ....!!!!
} else {
$item = $resource->getProperty('yagItem');
if (!$item instanceof \Tx_Yag_Domain_Model_Item) {
$pathInfo = new PathInfo($resource->getIdentifier());
$item = $this->getItem($pathInfo);
}
$publicUrl = $this->yagFileSystemDiv->getFileRelFileName($item->getSourceuri());
}
if ($relativeToCurrentScript) {
$publicUrl = PathUtility::getRelativePathTo(PathUtility::dirname(PATH_site . $publicUrl)) . PathUtility::basename($publicUrl);
}
return $publicUrl;
}
示例15: getPublicUrl
/**
* Returns a publicly accessible URL for a file.
*
* WARNING: Access to the file may be restricted by further means, e.g.
* some web-based authentication. You have to take care of this yourself.
*
* @param ResourceInterface $resourceObject The file or folder object
* @param bool $relativeToCurrentScript Determines whether the URL returned should be relative to the current script, in case it is relative at all (only for the LocalDriver)
* @return string
*/
public function getPublicUrl(ResourceInterface $resourceObject, $relativeToCurrentScript = false)
{
$publicUrl = null;
if ($this->isOnline()) {
// Pre-process the public URL by an accordant slot
$this->emitPreGeneratePublicUrlSignal($resourceObject, $relativeToCurrentScript, array('publicUrl' => &$publicUrl));
if ($publicUrl === null && $resourceObject instanceof File && ($helper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($resourceObject)) !== false) {
$publicUrl = $helper->getPublicUrl($resourceObject, $relativeToCurrentScript);
}
// If slot did not handle the signal, use the default way to determine public URL
if ($publicUrl === null) {
if ($this->hasCapability(self::CAPABILITY_PUBLIC)) {
$publicUrl = $this->driver->getPublicUrl($resourceObject->getIdentifier());
}
if ($publicUrl === null && $resourceObject instanceof FileInterface) {
$queryParameterArray = array('eID' => 'dumpFile', 't' => '');
if ($resourceObject instanceof File) {
$queryParameterArray['f'] = $resourceObject->getUid();
$queryParameterArray['t'] = 'f';
} elseif ($resourceObject instanceof ProcessedFile) {
$queryParameterArray['p'] = $resourceObject->getUid();
$queryParameterArray['t'] = 'p';
}
$queryParameterArray['token'] = GeneralUtility::hmac(implode('|', $queryParameterArray), 'resourceStorageDumpFile');
$publicUrl = 'index.php?' . str_replace('+', '%20', http_build_query($queryParameterArray));
}
// If requested, make the path relative to the current script in order to make it possible
// to use the relative file
if ($publicUrl !== null && $relativeToCurrentScript && !GeneralUtility::isValidUrl($publicUrl)) {
$absolutePathToContainingFolder = PathUtility::dirname(PATH_site . $publicUrl);
$pathPart = PathUtility::getRelativePathTo($absolutePathToContainingFolder);
$filePart = substr(PATH_site . $publicUrl, strlen($absolutePathToContainingFolder) + 1);
$publicUrl = $pathPart . $filePart;
}
}
}
return $publicUrl;
}