本文整理汇总了PHP中path::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP path::normalize方法的具体用法?PHP path::normalize怎么用?PHP path::normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类path
的用法示例。
在下文中一共展示了path::normalize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isWritable
/** Checks if the given directory is really writable. The standard PHP
* function is_writable() does not work properly on Windows servers
* @param string $dir
* @return bool */
public static function isWritable($dir)
{
$dir = path::normalize($dir);
if (!is_dir($dir)) {
return false;
}
$i = 0;
do {
$file = "{$dir}/is_writable_" . md5($i++);
} while (file_exists($file));
if (!@touch($file)) {
return false;
}
unlink($file);
return true;
}
示例2: getInexistantFilename
/** Get inexistant filename based on the given filename. If you skip $dir
* parameter the directory will be fetched from $filename and returned
* value will be full filename path. The third parameter is optional and
* defines the template, the filename will be renamed to. Default template
* is {name}({sufix}){ext}. Examples:
*
* file::getInexistantFilename("/my/directory/myfile.txt");
* If myfile.txt does not exist - returns the same path to the file
* otherwise returns "/my/directory/myfile(1).txt"
*
* file::getInexistantFilename("myfile.txt", "/my/directory");
* returns "myfile.txt" or "myfile(1).txt" or "myfile(2).txt" etc...
*
* file::getInexistantFilename("myfile.txt", "/dir", "{name}[{sufix}]{ext}");
* returns "myfile.txt" or "myfile[1].txt" or "myfile[2].txt" etc...
*
* @param string $filename
* @param string $dir
* @param string $tpl
* @return string */
static function getInexistantFilename($filename, $dir = null, $tpl = null)
{
if ($tpl === null) {
$tpl = "{name}({sufix}){ext}";
}
$fullPath = $dir === null;
if ($fullPath) {
$dir = path::normalize(dirname($filename));
} else {
$fdir = dirname($filename);
$dir = strlen($fdir) ? path::normalize("{$dir}/{$fdir}") : path::normalize($dir);
}
$filename = basename($filename);
$ext = self::getExtension($filename, false);
$name = strlen($ext) ? substr($filename, 0, -strlen($ext) - 1) : $filename;
$tpl = str_replace('{name}', $name, $tpl);
$tpl = str_replace('{ext}', strlen($ext) ? ".{$ext}" : "", $tpl);
$i = 1;
$file = "{$dir}/{$filename}";
while (file_exists($file)) {
$file = "{$dir}/" . str_replace('{sufix}', $i++, $tpl);
}
return $fullPath ? $file : (strlen($fdir) ? "{$fdir}/" . basename($file) : basename($file));
}
示例3: act_downloadClipboard
protected function act_downloadClipboard()
{
if (!isset($this->post['files']) || !is_array($this->post['files']) || $this->config['denyZipDownload']) {
$this->errorMsg("Unknown error.");
}
$zipFiles = array();
foreach ($this->post['files'] as $file) {
$file = path::normalize($file);
if (substr($file, 0, 1) == ".") {
continue;
}
$type = explode("/", $file);
$type = $type[0];
if ($type != $this->type) {
continue;
}
$file = $this->config['uploadDir'] . "/{$file}";
if (!is_file($file) || !is_readable($file)) {
continue;
}
$zipFiles[] = $file;
}
do {
$file = md5(time() . session_id());
$file = "{$this->config['uploadDir']}/{$file}.zip";
} while (file_exists($file));
$zip = new ZipArchive();
$res = $zip->open($file, ZipArchive::CREATE);
if ($res === TRUE) {
foreach ($zipFiles as $cfile) {
$zip->addFile($cfile, basename($cfile));
}
$zip->close();
}
header("Content-Type: application/x-zip");
header('Content-Disposition: attachment; filename="clipboard_' . basename($file) . '"');
header("Content-Length: " . filesize($file));
readfile($file);
unlink($file);
die;
}
示例4: makeThumb
protected function makeThumb($file, $overwrite = true)
{
$img = image::factory($this->imageDriver, $file);
// Drop files which are not images
if ($img->initError) {
return true;
}
$fimg = new fastImage($file);
$type = $fimg->getType();
$fimg->close();
if ($type === false) {
return true;
}
$thumb = substr($file, strlen($this->config['uploadDir']));
$thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb;
$thumb = path::normalize($thumb);
$thumbDir = dirname($thumb);
if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) {
return false;
}
if (!$overwrite && is_file($thumb)) {
return true;
}
// Images with smaller resolutions than thumbnails
if ($img->width <= $this->config['thumbWidth'] && $img->height <= $this->config['thumbHeight']) {
// Drop only browsable types
if (in_array($type, array("gif", "jpeg", "png"))) {
return true;
}
// Resize image
} elseif (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
return false;
}
// Save thumbnail
$options = array('file' => $thumb);
if ($type == "gif") {
$type = "jpeg";
}
if ($type == "jpeg") {
$options['quality'] = $this->config['jpegQuality'];
}
return $img->output($type, $options);
}
示例5: makeThumb
protected function makeThumb($file, $overwrite = true)
{
$gd = new gd($file);
// Drop files which are not GD handled images
if ($gd->init_error) {
return true;
}
$thumb = substr($file, strlen($this->config['uploadDir']));
$thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb;
$thumb = path::normalize($thumb);
$thumbDir = dirname($thumb);
if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) {
return false;
}
if (!$overwrite && is_file($thumb)) {
return true;
}
// Images with smaller resolutions than thumbnails
if ($gd->get_width() <= $this->config['thumbWidth'] && $gd->get_height() <= $this->config['thumbHeight']) {
$browsable = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG);
// Drop only browsable types
if (in_array($gd->type, $browsable)) {
return true;
}
// Resize image
} elseif (!$gd->resize_fit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
return false;
}
// Save thumbnail
return $gd->imagejpeg($thumb, $this->config['jpegQuality']);
}
示例6: makeThumb
protected function makeThumb($file, $overwrite = true)
{
$img = image::factory($this->imageDriver, $file);
// Drop files which are not images
if ($img->initError) {
return true;
}
$thumb = substr($file, strlen($this->config['uploadDir']));
$thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb;
$thumb = path::normalize($thumb);
$thumbDir = dirname($thumb);
if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) {
return false;
}
if (!$overwrite && is_file($thumb)) {
return true;
}
// Images with smaller resolutions than thumbnails
if ($img->width <= $this->config['thumbWidth'] && $img->height <= $this->config['thumbHeight']) {
list($tmp, $tmp, $type) = @getimagesize($file);
// Drop only browsable types
if (in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
return true;
}
// Resize image
} elseif (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
return false;
}
// Save thumbnail
return $img->output("jpeg", array('file' => $thumb, 'quality' => $this->config['jpegQuality']));
}
示例7: getInexistantFilename
/** Get inexistant filename based on the given filename. If you skip $dir
* parameter the directory will be fetched from $filename and returned
* value will be full filename path. The third parameter is optional and
* defines the template, the filename will be renamed to. Default template
* is {name}({sufix}){ext}. Examples:
*
* file::getInexistantFilename("/my/directory/myfile.txt");
* If myfile.txt does not exist - returns the same path to the file
* otherwise returns "/my/directory/myfile(1).txt"
*
* file::getInexistantFilename("myfile.txt", "/my/directory");
* returns "myfile.txt" or "myfile(1).txt" or "myfile(2).txt" etc...
*
* file::getInexistantFilename("myfile.txt", "/dir", "{name}[{sufix}]{ext}");
* returns "myfile.txt" or "myfile[1].txt" or "myfile[2].txt" etc...
*
* @param string $filename
* @param string $dir
* @param string $tpl
* @return string */
static function getInexistantFilename($filename, $dir = null, $tpl = null)
{
if ($tpl === null) {
$tpl = "{name}({sufix}){ext}";
}
$fullPath = $dir === null;
if ($fullPath) {
$dir = path::normalize(dirname($filename));
} else {
$fdir = dirname($filename);
$dir = strlen($fdir) ? path::normalize("{$dir}/{$fdir}") : path::normalize($dir);
}
$filename = basename($filename);
$ext = self::getExtension($filename, false);
$name = strlen($ext) ? substr($filename, 0, -strlen($ext) - 1) : $filename;
$tpl = str_replace('{name}', $name, $tpl);
$tpl = str_replace('{ext}', strlen($ext) ? ".{$ext}" : "", $tpl);
// Zuha Specific Update Start to Auto Make Filename Well Formed
$searches = array(' ', '!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "\$", ",", "?", "%", "#", "[", "]");
$replaces = array('-', '', '', "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
$filename = strtolower(str_replace($searches, $replaces, $filename));
$tpl = strtolower(str_replace($searches, $replaces, $tpl));
// Zuha Specific Update End
$i = 1;
$file = "{$dir}/{$filename}";
while (file_exists($file)) {
$file = "{$dir}/" . str_replace('{sufix}', $i++, $tpl);
}
return $fullPath ? $file : (strlen($fdir) ? "{$fdir}/" . basename($file) : basename($file));
}
示例8: makeThumb2
protected function makeThumb2($target, $fileUpload = null, $overwrite = true)
{
$gd = new gd($fileUpload);
// Drop files which are not GD handled images
if ($gd->init_error) {
return true;
}
$mpid = strtok($target, '/');
$thumb = str_replace($mpid, "{$mpid}/{$this->config['thumbsDir']}", $target);
$thumb = path::normalize($thumb);
//if (!$overwrite && is_file($thumb))
// return true;
// Resize image
if (!$gd->resize_fit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
return false;
}
// Save thumbnail
$temp = tempnam(sys_get_temp_dir(), uniqid());
if (!$gd->imagejpeg($temp, $this->config['jpegQuality'])) {
@unlink($temp);
return false;
}
$bucket = 'xinxintong';
$alioss = $this->get_alioss();
$rsp = $alioss->upload_file_by_file($bucket, $thumb, $temp);
@unlink($temp);
return true;
}