本文整理汇总了PHP中pathInfo函数的典型用法代码示例。如果您正苦于以下问题:PHP pathInfo函数的具体用法?PHP pathInfo怎么用?PHP pathInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pathInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_upfile_url
/**
* 获取附件文件URL
* @param string $url
* @param string $suffix
* @param string $path
*/
function get_upfile_url($url, $suffix = '', $path = '')
{
if (empty($url)) {
return;
}
if (!empty($suffix)) {
$info = pathInfo($url);
$url = $info['dirname'] . '/' . $info['filename'] . '_' . $suffix . '.' . $info['extension'];
}
$tmpl = C('TMPL_PARSE_STRING');
if (is_int($path)) {
$path = $tmpl['__ALBUM' . $path . '__'];
} elseif (empty($path)) {
$search = array('__COMMON__', '__SD__', '__HD__', '__THEME__');
$replace = array($tmpl['__COMMON__'], $tmpl['__SD__'], $tmpl['__HD__'], $tmpl['__THEME__']);
foreach (C('ALBUM_TYPE') as $key => $v) {
$search[] = 'album' . $key;
$replace[] = 'album' . $tmpl[$key];
}
$url = str_replace($search, $replace, $url);
if (substr($url, 0, 1) == '/' || substr($url, 0, 2) == './' || substr($url, 0, 3) == '../' || substr($url, 0, 7) == 'http://' || substr($url, 0, 8) == 'https://' || substr($url, 0, 6) == 'ftp://') {
return $url;
} else {
$path = $tmpl['__UPFILE__'];
}
}
if (substr($path, -1) != '/') {
$path .= '/';
}
return $path . $url;
}
示例2: image_createThumb
function image_createThumb($src, $dest, $maxWidth, $maxHeight, $quality = 75)
{
if (file_exists($src) && isset($dest)) {
// path info
$destInfo = pathInfo($dest);
// image src size
$srcSize = getImageSize($src);
// image dest size $destSize[0] = width, $destSize[1] = height
$srcRatio = $srcSize[0] / $srcSize[1];
// width/height ratio
$destRatio = $maxWidth / $maxHeight;
if ($destRatio > $srcRatio) {
$destSize[1] = $maxHeight;
$destSize[0] = $maxHeight * $srcRatio;
} else {
$destSize[0] = $maxWidth;
$destSize[1] = $maxWidth / $srcRatio;
}
// path rectification
if ($destInfo['extension'] == "gif") {
$dest = substr_replace($dest, 'jpg', -3);
}
// true color image, with anti-aliasing
$destImage = imageCreateTrueColor($destSize[0], $destSize[1]);
// imageAntiAlias($destImage,true);
// src image
switch ($srcSize[2]) {
case 1:
//GIF
$srcImage = imageCreateFromGif($src);
break;
case 2:
//JPEG
$srcImage = imageCreateFromJpeg($src);
break;
case 3:
//PNG
$srcImage = imageCreateFromPng($src);
break;
default:
return false;
break;
}
// resampling
imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]);
// generating image
switch ($srcSize[2]) {
case 1:
case 2:
imageJpeg($destImage, $dest, $quality);
break;
case 3:
imagePng($destImage, $dest);
break;
}
return true;
} else {
return 'No such File';
}
}
示例3: getThumbFilename
/**
*
* get filename for thumbnail save / retrieve
* TODO: do input validations - security measures
*/
private function getThumbFilename()
{
$info = pathInfo($this->filename);
//add dirname as postfix (if exists)
$postfix = "";
$dirname = UniteFunctionsRev::getVal($info, "dirname");
if (!empty($dirname)) {
$postfix = str_replace("/", "-", $dirname);
}
$ext = $info["extension"];
$name = $info["filename"];
$width = ceil($this->maxWidth);
$height = ceil($this->maxHeight);
$thumbFilename = $name . "_" . $width . "x" . $height;
if (!empty($this->type)) {
$thumbFilename .= "_" . $this->type;
}
if (!empty($this->effect)) {
$thumbFilename .= "_e" . $this->effect;
if (!empty($this->effect_arg1)) {
$thumbFilename .= "x" . $this->effect_arg1;
}
}
//add postfix
if (!empty($postfix)) {
$thumbFilename .= "_" . $postfix;
}
$thumbFilename .= "." . $ext;
return $thumbFilename;
}
示例4: validateExtension
/**
* @param $name
* @throws InvalidArgumentException
*/
private function validateExtension($name)
{
$pathInfo = pathInfo($name);
if (!array_key_exists('extension', $pathInfo)) {
throw new InvalidArgumentException("Image extension can't be empty.");
}
if (!in_array($pathInfo['extension'], $this->availableExtensions)) {
throw new InvalidArgumentException("Image needs to have jpeg extension.");
}
}
示例5: zipDir
/**
* Zip a folder (including itself).
* Usage:
* <code>HZip::zipDir('/path/to/sourceDir', '/path/to/out.zip');</code>
*
* @param string $sourcePath Path of directory to be zip.
* @param string $outZipPath Path of output zip file.
*/
public static function zipDir($sourcePath, $outZipPath)
{
$pathInfo = pathInfo($sourcePath);
$parentPath = $pathInfo['dirname'];
$dirName = $pathInfo['basename'];
$z = new ZipArchive();
$z->open($outZipPath, ZIPARCHIVE::CREATE);
$z->addEmptyDir($dirName);
self::folderToZip($sourcePath, $z, strlen($sourcePath) - strlen($dirName));
$z->close();
}
示例6: run
/**
* @param string[] $args
* @return void
*/
public function run(array $args)
{
if (0 == count($args)) {
$this->stop('Please pass new configuration name and it\'s parent(s)', 1);
}
if (1 == count($args)) {
$this->stop('Please pass new configuration parent(s) or string NONE if no parents', 1);
}
$name = $args[0];
$parents = $args;
$base = $this->getApplication()->rootDir . DIRECTORY_SEPARATOR . 'settings';
$new = $base . DIRECTORY_SEPARATOR . $name;
array_shift($parents);
if (file_exists($new)) {
echo 'Using setup directory', PHP_EOL, "\t", $new, PHP_EOL;
} else {
echo 'Creating new setup directory', PHP_EOL, "\t", $new, PHP_EOL;
mkDir($new, 0755, true);
}
if (in_array('NONE', $parents)) {
echo "\t\t", 'no parents', PHP_EOL;
$parents = array();
} else {
file_put_contents($new . DIRECTORY_SEPARATOR . \Nano\Application\Config\Builder::PARENTS_FILE, '<?php return ' . var_export($parents, true) . ';');
echo "\t\t", \Nano\Application\Config\Builder::PARENTS_FILE, PHP_EOL;
}
foreach ($parents as $parent) {
$i = new \DirectoryIterator($base . DIRECTORY_SEPARATOR . $parent);
foreach ($i as $file) {
if ($file->isDir() || $file->isDir() || !$file->isReadable()) {
continue;
}
if (\Nano\Application\Config\Builder::PARENTS_FILE === $file->getBaseName()) {
continue;
}
if (\Nano\Application\Config\Builder::ROUTES_FILE === $file->getBaseName()) {
continue;
}
if ('php' !== pathInfo($file->getBaseName(), PATHINFO_EXTENSION)) {
continue;
}
$newFile = $new . DIRECTORY_SEPARATOR . $file->getBaseName();
if (file_exists($newFile)) {
continue;
}
file_put_contents($newFile, '<?php return array(' . PHP_EOL . ');');
echo "\t\t", $file->getBaseName(), PHP_EOL;
}
}
echo "\t\t", \Nano\Application\Config\Builder::ROUTES_FILE, PHP_EOL;
file_put_contents($new . DIRECTORY_SEPARATOR . \Nano\Application\Config\Builder::ROUTES_FILE, '<?php' . PHP_EOL . PHP_EOL);
echo 'Done', PHP_EOL;
}
示例7: iterate
/**
* @param $path
* @param $subjects
* @param $namespace
*/
private function iterate($path, $subjects, $namespace)
{
foreach ($subjects as $subject) {
$pathInfo = pathInfo($subject);
if (is_dir($subject)) {
$this->searchDir($path . '/' . $pathInfo['basename'], $namespace . '\\' . $pathInfo['basename']);
} else {
if ($pathInfo['extension'] === 'php' && $pathInfo['filename'] !== 'BaseRoute') {
$this->routes[] = $namespace . '\\' . $pathInfo['filename'];
}
}
}
}
示例8: zip
public static function zip($sourcePath, $outZipPath, $isDirectory = true)
{
$pathInfo = pathInfo($sourcePath);
$parentPath = $pathInfo['dirname'];
$dirName = $pathInfo['basename'];
$z = new ZipArchive();
$z->open($outZipPath, ZIPARCHIVE::CREATE);
if ($isDirectory) {
$z->addEmptyDir($dirName);
self::folderToZip($sourcePath, $z, strlen("{$parentPath}/"));
} else {
$z->addFile($sourcePath, $dirName);
}
return $z->close();
}
示例9: compressFolder
/**
* @access public
* @author "Lionel Lecaque, <lionel@taotesting.com>"
* @param string $src
* @param string $dest
* @param string $includeDir
*/
public static function compressFolder($src, $dest, $includeDir = false)
{
$pathInfo = pathInfo($src);
$parentPath = $pathInfo['dirname'];
$dirName = $pathInfo['basename'];
$z = new ZipArchive();
$z->open($dest, ZipArchive::OVERWRITE);
$exclusiveLength = strlen("{$src}/");
if ($includeDir) {
$z->addEmptyDir($dirName);
$exclusiveLength = strlen("{$parentPath}/");
}
self::folderToZip($src, $z, $exclusiveLength);
$z->close();
}
示例10: ckeup
public function ckeup()
{
$targetFolder = '/public/uploads';
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = $targetPath . '/' . $_FILES['upload']['name'];
$fileTypes = array('jpg', 'jpeg', 'gif', 'png');
$uploadFilename = $_FILES['upload']['name'];
$extensions = pathInfo($uploadFilename, PATHINFO_EXTENSION);
if (in_array($extensions, $fileTypes)) {
move_uploaded_file($_FILES['upload']['tmp_name'], $targetFile);
$previewname = $targetFile;
$callback = $_REQUEST["CKEditorFuncNum"];
echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$callback},'" . $previewname . "','');</script>";
// Array ( [upload] => Array ( [name] => 123.png [type] => image/png [tmp_name] => F:\uploads\php41FF.tmp [error] => 0 [size] => 11857 ) )
}
}
示例11: upload
/**
* 富文本的图片上传功能,基于ckedit
* 配置路径在/public/packages/frozennode/administrator/js/ckedit/config.js
*/
public function upload()
{
$extensions = array('jpg', 'bmp', 'gif', 'png');
$uploadFilename = $_FILES['upload']['name'];
$extension = pathInfo($uploadFilename, PATHINFO_EXTENSION);
if (in_array($extension, $extensions)) {
$uploadPath = public_path() . '/uploads/products/article/';
$uuid = str_replace('.', '', uniqid("", TRUE)) . "." . $extension;
$desname = $uploadPath . $uuid;
$previewname = '/uploads/products/article/' . $uuid;
$tag = move_uploaded_file($_FILES['upload']['tmp_name'], $desname);
$callback = $_REQUEST["CKEditorFuncNum"];
echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$callback},'" . $previewname . "','');</script>";
} else {
echo "<font color=\"red\"size=\"2\">*文件格式不正确(必须为.jpg/.gif/.bmp/.png文件)</font>";
}
}
示例12: init
public function init()
{
$Directory = new RecursiveDirectoryIterator(APPPATH . 'modules');
$Iterator = new RecursiveIteratorIterator($Directory);
$Models = new RegexIterator($Iterator, '/^.+\\_dashboard_model.php$/i', RecursiveRegexIterator::GET_MATCH);
foreach ($Models as $k => $v) {
$this->_modules[] = $k;
}
$this->_exceptions[] = '';
// nothing at the moment...
$this->_modules = array_diff($this->_modules, $this->_exceptions);
foreach ($this->_modules as $k => $v) {
$classname = pathInfo($v, PATHINFO_FILENAME);
if (is_file($v)) {
$this->CI->load->file($v);
}
$this->CI->load->file(FCPATH . APPPATH . '/modules/users/helpers/dashboard_helper.php');
$class = new $classname();
}
}
示例13: run
/**
* @return void
* @param string[] $args
*/
public function run(array $args)
{
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getApplication()->rootDir), \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $file) {
/** @var \DirectoryIterator $file */
if ($file->isDir()) {
continue;
}
if ('php' != pathInfo($file->getBaseName(), PATHINFO_EXTENSION)) {
continue;
}
$source = file_get_contents($file->getPathName());
$result = $this->convertLineEnds($source);
$result = $this->removeTrailingSpaces($result);
$result = $this->convertIndentationSpaces($result);
if ($source === $result) {
continue;
}
file_put_contents($file->getPathName(), $result);
echo $file->getPathName(), PHP_EOL;
}
}
示例14: __construct
/**
* Constructor
*
* @param PHPRtfLite $rtf
* @param string $imageFile image file incl. path
* @param float $width
* @param flaot $height
*/
public function __construct(PHPRtfLite $rtf, $imageFile, PHPRtfLite_ParFormat $parFormat = null, $width = null, $height = null)
{
$this->_rtf = $rtf;
$this->_parFormat = $parFormat;
if (file_exists($imageFile)) {
$this->_file = $imageFile;
$pathInfo = pathInfo($imageFile);
if (isset($pathInfo['extension'])) {
$this->_extension = strtolower($pathInfo['extension']);
}
list($this->_defaultWidth, $this->_defaultHeight) = getimagesize($imageFile);
if ($width !== null) {
$this->setWidth($width);
}
if ($height !== null) {
$this->setHeight($height);
}
} else {
$this->_defaultWidth = 20;
$this->_defaultHeight = 20;
$this->_extension = 'png';
}
}
示例15: set
/**
* {@inheritDoc}
*/
public function set($key, $value)
{
$pathInfo = pathInfo($this->cachedFile());
$cacheDir = $pathInfo['dirname'];
$fileName = $pathInfo['basename'];
ErrorHandler::start();
if (!is_dir($cacheDir)) {
$umask = umask(0);
mkdir($cacheDir, 0777, true);
umask($umask);
// @codeCoverageIgnoreStart
}
// @codeCoverageIgnoreEnd
ErrorHandler::stop();
if (!is_writable($cacheDir)) {
throw new RuntimeException('Unable to write file ' . $this->cachedFile());
}
// Use "rename" to achieve atomic writes
$tmpFilePath = $cacheDir . '/AssetManagerFilePathCache_' . $fileName;
if (@file_put_contents($tmpFilePath, $value, LOCK_EX) === false) {
throw new RuntimeException('Unable to write file ' . $this->cachedFile());
}
rename($tmpFilePath, $this->cachedFile());
}