本文整理汇总了PHP中FileUtil::removeTrailingSlash方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::removeTrailingSlash方法的具体用法?PHP FileUtil::removeTrailingSlash怎么用?PHP FileUtil::removeTrailingSlash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtil
的用法示例。
在下文中一共展示了FileUtil::removeTrailingSlash方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: promptPackageDir
/**
* Prompts for installation directory.
*
* @return string package dir
*/
protected function promptPackageDir()
{
$packageDir = $errorField = $errorType = '';
if (isset($_POST['send'])) {
if (isset($_POST['packageDir'])) {
$packageDir = StringUtil::trim($_POST['packageDir']);
}
// error handling
try {
$dir = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator($packageDir));
// package can not be installed into the wcf directory
if (FileUtil::unifyDirSeperator(WCF_DIR) == $dir) {
throw new UserInputException('packageDir', 'wcfDirLocked');
}
// this package is a standalone package and needs its own package directory
$relativePackageDir = FileUtil::getRelativePath(WCF_DIR, $dir);
$sql = "SELECT \tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\tWHERE\tpackageDir = '" . escapeString($relativePackageDir) . "'";
$alreadyInstalled = WCF::getDB()->getFirstRow($sql);
if ($alreadyInstalled['count'] > 0) {
throw new UserInputException('packageDir', 'alreadyInstalled');
}
// check writing property
if (@file_exists($dir) && !@is_writable($dir)) {
throw new UserInputException('packageDir', 'notWritable');
}
return $relativePackageDir;
} catch (UserInputException $e) {
$errorField = $e->getField();
$errorType = $e->getType();
}
} else {
// make default dir
//$packageNameParts = explode('.', $this->installation->getPackage()->getPackage());
//$packageDir = FileUtil::getRealPath(WCF_DIR.'../'.$packageNameParts[count($packageNameParts) - 1]);
$packageDir = FileUtil::getRealPath(WCF_DIR . '../');
}
// domain
$domainName = '';
if (!empty($_SERVER['SERVER_NAME'])) {
$domainName = 'http://' . $_SERVER['SERVER_NAME'];
}
// port
if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) {
$domainName .= ':' . $_SERVER['SERVER_PORT'];
}
// wcf url
$wcfUrl = '';
if (!empty($_SERVER['REQUEST_URI'])) {
$wcfUrl = FileUtil::removeTrailingSlash(FileUtil::getRealPath(FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash(dirname($_SERVER['REQUEST_URI']))) . '/' . RELATIVE_WCF_DIR));
}
WCF::getTPL()->assign(array('packageDir' => $packageDir, 'errorField' => $errorField, 'errorType' => $errorType, 'domainName' => $domainName, 'wcfUrl' => $wcfUrl, 'wcfDir' => FileUtil::unifyDirSeperator(WCF_DIR)));
WCF::getTPL()->display('packageInstallationPromptPackageDir');
exit;
}
示例2: getRelativeFtpPath
/**
* Searches a relative path emanating from an absolute installation path.
*
* @param FTP $ftp
* @param string $installPath
* @return string $relativeFtpPath
*/
public static function getRelativeFtpPath(FTP $ftp, $installPath)
{
// write a zero byte test file to the presumptive root of the ftp server.
$installPath = FileUtil::unifyDirSeperator($installPath);
$destFile = self::writeDummyFile($ftp);
$pathPrefix = '';
if (!$destFile) {
// loop through folders to find a writable directory
$pathSegments = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($installPath)));
foreach ($pathSegments as $path) {
if (@$ftp->chdir($path)) {
$pathPrefix .= $path . '/';
if ($destFile = self::writeDummyFile($ftp)) {
for ($i = 0; $i < substr_count($pathPrefix, '/'); $i++) {
$ftp->cdup();
}
break;
}
} else {
if (!empty($pathPrefix)) {
return null;
}
}
}
}
// search given installation path for that file.
$pathSegments = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($installPath)));
while (count($pathSegments) != 0) {
if (preg_match('/^WIN/i', PHP_OS)) {
$currentDir = FileUtil::addTrailingSlash(implode($pathSegments, '/'));
} else {
$currentDir = '/' . FileUtil::addTrailingSlash(implode($pathSegments, '/'));
}
if (@file_exists($currentDir . $destFile)) {
$basePath = $currentDir;
break;
} else {
array_pop($pathSegments);
}
}
if ($pathPrefix . $destFile) {
$ftp->delete($pathPrefix . $destFile);
}
// return the rest of the path which must be the relative path.
$relativeFtpPath = FileUtil::addTrailingSlash($pathPrefix . str_replace($currentDir, '', $installPath));
return $relativeFtpPath;
}
示例3: searchWcfDir
/**
* Searches the wcf dir.
*/
protected function searchWcfDir()
{
$foundDirectory = '';
if (self::$wcfDir) {
$wcfDir = self::$wcfDir;
} else {
if ($foundDirectory = FileUtil::scanFolder(INSTALL_SCRIPT_DIR, "WCF.class.php", true)) {
$foundDirectory = $wcfDir = FileUtil::unifyDirSeperator(dirname(dirname(dirname($foundDirectory))) . '/');
} else {
$wcfDir = FileUtil::unifyDirSeperator(INSTALL_SCRIPT_DIR) . 'wcf/';
}
}
// domain
$domainName = '';
if (!empty($_SERVER['SERVER_NAME'])) {
$domainName = 'http://' . $_SERVER['SERVER_NAME'];
}
// port
if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) {
$domainName .= ':' . $_SERVER['SERVER_PORT'];
}
// script url
$installScriptUrl = '';
if (!empty($_SERVER['REQUEST_URI'])) {
$installScriptUrl = FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash(FileUtil::unifyDirSeperator(dirname($_SERVER['REQUEST_URI']))));
}
WCF::getTPL()->assign(array('nextStep' => 'unzipFiles', 'foundDirectory' => $foundDirectory, 'wcfDir' => $wcfDir, 'domainName' => $domainName, 'installScriptUrl' => $installScriptUrl, 'installScriptDir' => FileUtil::unifyDirSeperator(INSTALL_SCRIPT_DIR)));
WCF::getTPL()->display('stepSearchWcfDir');
}
示例4: install
/**
* Starts the extracting of the files.
*/
protected function install()
{
$this->checkTargetDir();
$this->createTargetDir();
// open source archive
$tar = new Tar($this->source);
// distinct directories and files
$directories = array();
$files = array();
foreach ($tar->getContentList() as $index => $file) {
if (empty($this->folder) || StringUtil::indexOf($file['filename'], $this->folder) === 0) {
if (!empty($this->folder)) {
$file['filename'] = StringUtil::replace($this->folder, '', $file['filename']);
}
// remove leading slash
$file['filename'] = FileUtil::removeLeadingSlash($file['filename']);
if ($file['type'] == 'folder') {
// remove trailing slash
$directories[] = FileUtil::removeTrailingSlash($file['filename']);
} else {
$files[$index] = $file['filename'];
}
}
}
$this->checkFiles($files);
// now create the directories
$errors = array();
foreach ($directories as $dir) {
try {
$this->createDir($dir);
} catch (SystemException $e) {
$errors[] = array('file' => $dir, 'code' => $e->getCode(), 'message' => $e->getMessage());
}
}
// now untar all files
foreach ($files as $index => $file) {
try {
$this->createFile($file, $index, $tar);
} catch (SystemException $e) {
$errors[] = array('file' => $file, 'code' => $e->getCode(), 'message' => $e->getMessage());
}
}
if (count($errors) > 0) {
throw new SystemException('error(s) during the installation of the files.', 11111, $errors);
}
$this->logFiles($files);
// close tar
$tar->close();
}