本文整理汇总了PHP中stripDirectory函数的典型用法代码示例。如果您正苦于以下问题:PHP stripDirectory函数的具体用法?PHP stripDirectory怎么用?PHP stripDirectory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stripDirectory函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: glueDirectories
function glueDirectories($part1, $part2)
{
// --------------
// Returns the 2 dirs glued together in the format
// /home/dh1234/test (leading /, NO trailing /)
// \\server\web\mysite.com\net2ftp
// --------------
// Strip leading and trailing / and \
// Take Windows shared directory into account \\server\web\mysite.com\net2ftp
if (substr($part1, 0, 2) == "\\\\") {
$part1 = "\\\\" . stripDirectory($part1);
} else {
$part1 = stripDirectory($part1);
}
if (substr($part2, 0, 2) == "\\\\") {
$part2 = "\\\\" . stripDirectory($part2);
} else {
$part2 = stripDirectory($part2);
}
// Length
$part1_len = strlen($part1);
$part2_len = strlen($part2);
// Check if Unix or Windows style directories are used
if ($part1_len > 1 && (substr($part1, 1, 1) == ":" || substr($part1, 0, 2) == "\\\\")) {
$system = "windows";
} elseif ($part2_len > 1 && (substr($part2, 1, 1) == ":" || substr($part1, 0, 2) == "\\\\")) {
$system = "windows";
} else {
$system = "unix";
}
// Glue the 2 parts together
if ($part1_len > 0 && $part2_len > 0) {
if ($system == "windows") {
return $part1 . "\\" . $part2;
} else {
return "/" . $part1 . "/" . $part2;
}
} elseif (($part1_len == 0 || $part1 == "/" || $part1 == "\\") && $part2_len > 0) {
if ($system == "windows") {
return $part2;
} else {
return "/" . $part2;
}
} elseif (($part2_len == 0 || $part2 == "/" || $part2 == "\\") && $part1_len > 0) {
if ($system == "windows") {
return $part1;
} else {
return "/" . $part1;
}
} else {
return "";
}
}
示例2: net2ftp_module_printBody
function net2ftp_module_printBody()
{
// --------------
// This function prints the browse screen ($state2=="main") or the directory popup screen ($state2=="popup")
// For the browse screen ($state2=="main"), 2 template files are called
// --------------
// -------------------------------------------------------------------------
// Global variables
// -------------------------------------------------------------------------
global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result;
// -------------------------------------------------------------------------
// Check if the directory name contains \' and if it does, print an error message
// Note: these directories cannot be browsed, but can be deleted
// -------------------------------------------------------------------------
// if (strstr($directory, "\'") != false) {
// $errormessage = __("Directories with names containing \' cannot be displayed correctly. They can only be deleted. Please go back and select another subdirectory.");
// setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
// return false;
// }
// -------------------------------------------------------------------------
// Variables
// With status update if $state2=="main"
// -------------------------------------------------------------------------
// ------------------------------------
// Open connection
// ------------------------------------
if ($net2ftp_globals["state2"] == "main") {
setStatus(2, 10, __("Connecting to the FTP server"));
}
$conn_id = ftp_openconnection();
if ($net2ftp_result["success"] == false) {
return false;
}
// ------------------------------------
// Get raw list of directories and files; parse the raw list and return a nice list
// This function may change the current $directory; a warning message is returned in that case
// ------------------------------------
if ($net2ftp_globals["state2"] == "main") {
setStatus(4, 10, __("Getting the list of directories and files"));
}
$list = ftp_getlist($conn_id, $net2ftp_globals["directory"]);
if ($net2ftp_result["success"] == false) {
return false;
}
// ------------------------------------
// Close connection
// ------------------------------------
ftp_closeconnection($conn_id);
// ------------------------------------
// Sort the list
// ------------------------------------
$list_directories = sort_list($list["directories"]);
$list_files = sort_list($list["files"]);
$list_symlinks = sort_list($list["symlinks"]);
$list_unrecognized = sort_list($list["unrecognized"]);
$warning_directory = $list["stats"]["warnings"];
$directory = $list["stats"]["newdirectory"];
$directory_html = htmlEncode2($directory);
$directory_url = urlEncode2($directory);
$directory_js = javascriptEncode2($directory);
$updirectory = upDir($directory);
$updirectory_html = htmlEncode2($updirectory);
$updirectory_url = urlEncode2($updirectory);
$updirectory_js = javascriptEncode2($updirectory);
// ------------------------------------
// Calculate the list of HTTP URLs
// ------------------------------------
if ($net2ftp_globals["state2"] == "main") {
$list_links_js = ftp2http($net2ftp_globals["directory"], $list_files, "no");
$list_links_url = ftp2http($net2ftp_globals["directory"], $list_files, "yes");
}
// ------------------------------------
// Consumption message
// ------------------------------------
$warning_consumption = "";
if (checkConsumption() == false) {
$warning_consumption .= "<b>" . __("Daily limit reached: you will not be able to transfer data") . "</b><br /><br />\n";
$warning_consumption .= __("In order to guarantee the fair use of the web server for everyone, the data transfer volume and script execution time are limited per user, and per day. Once this limit is reached, you can still browse the FTP server but not transfer data to/from it.") . "<br /><br />\n";
$warning_consumption .= __("If you need unlimited usage, please install net2ftp on your own web server.") . "<br />\n";
}
// ------------------------------------
// Browse message
// ------------------------------------
if ($net2ftp_settings["message_browse"] != "" && $net2ftp_settings["message_browse"] != "Setting message_browse does not exist") {
$warning_message = $net2ftp_settings["message_browse"];
}
// ------------------------------------
// Directory tree
// ------------------------------------
$directory_exploded = explode("/", stripDirectory($directory));
if ($directory != "/" && checkAuthorizedDirectory("/") == true) {
$directory_tree = "<a href=\"javascript:submitBrowseForm('/','','browse','main');\">root</a> ";
} else {
$directory_tree = "root ";
}
$directory_goto = "";
for ($i = 0; $i < sizeof($directory_exploded) - 1; $i++) {
$directory_goto = glueDirectories($directory_goto, $directory_exploded[$i]);
$directory_goto_url = urlEncode2($directory_goto);
if (checkAuthorizedDirectory($directory_goto) == true) {
//.........这里部分代码省略.........
示例3: validateDirectory
function validateDirectory($directory)
{
// --------------
// Input: "/dir1/dir2/dir3/../../dir4/dir5"
// Output: "/dir1/dir4/dir5"
// Remove the following characters \/:*?"<>|
// --------------
// -------------------------------------------------------------------------
// Nothing to do if the directory is the root directory
// -------------------------------------------------------------------------
if ($directory == "") {
return "";
} elseif ($directory == "/") {
return "/";
}
// -------------------------------------------------------------------------
// Remove XSS code
// -------------------------------------------------------------------------
// $directory = RemoveXSS($directory);
// -------------------------------------------------------------------------
// Check if the directory contains ".."
// -------------------------------------------------------------------------
if (strpos($directory, "..") === false) {
$directory = "/" . stripDirectory($directory);
} else {
$directory = stripDirectory($directory);
// Split down into parts
// directoryparts[0] contains the first part, directoryparts[1] the second,...
$directoryparts = explode("/", $directory);
// Start from the end
// If you encounter N times a "..", do not take into account the next N parts which are not ".."
// Example: "/dir1/dir2/dir3/../../dir4/dir5" ----> "/dir1/dir4/dir5"
$doubledotcounter = 0;
$newdirectory = "";
$sizeof_directoryparts = sizeof($directoryparts);
for ($i = $sizeof_directoryparts - 1; $i >= 0; $i = $i - 1) {
if ($directoryparts[$i] == "..") {
$doubledotcounter = $doubledotcounter + 1;
} else {
if ($doubledotcounter == 0) {
$newdirectory = $directoryparts[$i] . "/" . $newdirectory;
} elseif ($doubledotcounter > 0) {
$doubledotcounter = $doubledotcounter - 1;
}
// Don't add the part, and reduce the counter by 1
}
}
// end for
$directory = "/" . stripDirectory($newdirectory);
}
// end if else
// Remove : * ? " < > |
// $directory = preg_replace("/[\\:\\*\\?\\\"\\<\\>\\|]/", "", $directory);
// Remove : * ? < > |
$directory = preg_replace("/[\\:\\*\\?\\<\\>\\|]/", "", $directory);
return $directory;
}
示例4: isSubdirectory
function isSubdirectory($parentdir, $childdir)
{
// --------------
// Returns true if the childdir is a subdirectory of the parentdir
// --------------
// If the parentdir is empty or the root directory, then the childdir is
// a the same as or a subdirectory of the parentdir
if ($parentdir == "" || $parentdir == "/" || $parentdir == "\\") {
return true;
}
// Strip the directories of leading and trailing slashes
$parentdir = stripDirectory($parentdir);
$childdir = stripDirectory($childdir);
$parentdir_length = strlen($parentdir);
// Check if the first characters of the childdir are different from the
// parentdir. Example:
// parentdir: /home/abc
// childdir: /home/blabla ==> false
// childdir: /home/abcd ==> continue further checks
// childdir: /home/abc/xyz ==> continue further checks
$childdir_firstchars = substr($childdir, 0, $parentdir_length);
if ($childdir_firstchars != $parentdir) {
return false;
}
// If the first characters of the childdir are identical to the parentdir,
// check if the first next character of the childdir name is different.
// Example:
// parentdir: /home/abc
// childdir: /home/abcd ==> false
// childdir: /home/abc/xyz ==> true
$childdir_nextchar = substr($childdir, $parentdir_length, 1);
if ($childdir_nextchar != "/" && $childdir_nextchar != "\\") {
return false;
}
return true;
}
示例5: ftp_getlist
function ftp_getlist($conn_id, $directory)
{
// --------------
// This function connects to the FTP server and returns an array with a list of directories and files.
// One row per directory or file, with rows from index 1 to n
//
// Step 1: send ftp_rawlist request to the FTP server; this returns a string
// Step 2: parse that string and get a first array ($templist)
// Step 3: move the rows to another array, to index 1 to n ($list)
//
// This function is used in all functions which process directories recursively.
// --------------
// -------------------------------------------------------------------------
// Global variables
// -------------------------------------------------------------------------
global $net2ftp_globals, $net2ftp_settings;
// -------------------------------------------------------------------------
// Initialization
// -------------------------------------------------------------------------
$warnings = "";
// -------------------------------------------------------------------------
// Step 1: Chdir to the directory and get the current directory
// -------------------------------------------------------------------------
// ----------------------------------------------
// Step 1a - Directory is "/"
// Chdir to the directory because otherwise the ftp_rawlist does not work on some FTP servers
// ----------------------------------------------
if ($directory == "/") {
$result1a = @ftp_chdir($conn_id, $directory);
} elseif ($directory == "") {
$result1b = @ftp_chdir($conn_id, $directory);
$directory = @ftp_pwd($conn_id);
} else {
// 1c1 - Replace \' by \\' to be able to delete directories with names containing \'
$directory1 = str_replace("\\'", "\\\\'", $directory);
// 1c2 - Chdir to the directory
// This is to check if the directory exists, but also because otherwise
// the ftp_rawlist does not work on some FTP servers.
$result1c = @ftp_chdir($conn_id, $directory1);
// 1c3 - If the first ftp_chdir returns false, try a second time without the leading /
// Some Windows FTP servers do not work when you use a leading /
if ($result1c == false) {
$directory2 = stripDirectory($directory1);
$result2 = @ftp_chdir($conn_id, $directory2);
// 1c3 - If the second ftp_chdir also does not work:
// For the Browse screen ==> go to the user's root directory
// For all other screens ==> return error
if ($result2 == false) {
if ($net2ftp_globals["state"] == "browse") {
$rootdirectory = getRootdirectory();
// User's root directory is different from the current directory, so switch to it
if ($directory != $rootdirectory) {
$warnings .= __("The directory <b>%1\$s</b> does not exist or could not be selected, so the directory <b>%2\$s</b> is shown instead.", $directory, $rootdirectory);
$directory = $rootdirectory;
$result3 = @ftp_chdir($conn_id, $directory);
} else {
$errormessage = __("Your root directory <b>%1\$s</b> does not exist or could not be selected.", $directory);
setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
}
} else {
$errormessage = __("The directory <b>%1\$s</b> could not be selected - you may not have sufficient rights to view this directory, or it may not exist.", $directory);
setErrorVars(false, $errormessage, debug_backtrace(), __FILE__, __LINE__);
}
}
// end if result2
}
// end if result1
}
// end if / or "" or else
// -------------------------------------------------------------------------
// Step 2 - Get list of directories and files
// The -a option is used to show the hidden files as well on some FTP servers
// Some servers do not return anything when using -a, so in that case try again without the -a option
// -------------------------------------------------------------------------
$rawlist = ftp_rawlist($conn_id, "-a");
if (sizeof($rawlist) <= 1) {
$rawlist = ftp_rawlist($conn_id, "");
}
// -------------------------------------------------------------------------
// Step 3 - Parse the raw list
// -------------------------------------------------------------------------
// ----------------------------------------------
// Initialize variables
// ----------------------------------------------
$list["directories"] = array();
$list["files"] = array();
$list["symlinks"] = array();
$list["unrecognized"] = array();
$directory_index = 1;
$file_index = 1;
$symlink_index = 1;
$unrecognized_index = 1;
$list["stats"]["directories"]["total_number"] = 0;
$list["stats"]["directories"]["total_size"] = 0;
$list["stats"]["directories"]["total_skipped"] = 0;
$list["stats"]["files"]["total_number"] = 0;
$list["stats"]["files"]["total_size"] = 0;
$list["stats"]["files"]["total_skipped"] = 0;
$list["stats"]["symlinks"]["total_number"] = 0;
$list["stats"]["symlinks"]["total_size"] = 0;
//.........这里部分代码省略.........
示例6: glueDirectories
function glueDirectories($part1, $part2)
{
// --------------
// Returns the 2 dirs glued together in the format /home/dh1234/test (leading /, NO trailing /)
// --------------
// Strip leading and trailing / and \
$part1 = stripDirectory($part1);
$part2 = stripDirectory($part2);
// Length
$part1_len = strlen($part1);
$part2_len = strlen($part2);
// Check if Unix or Windows style directories are used
if ($part1_len > 1 && substr($part1, 1, 1) == ":") {
$system = "windows";
} elseif ($part2_len > 1 && substr($part2, 1, 1) == ":") {
$system = "windows";
} else {
$system = "unix";
}
// Glue the 2 parts together
if ($part1_len > 0 && $part2_len > 0) {
if ($system == "windows") {
return $part1 . "\\" . $part2;
} else {
return "/" . $part1 . "/" . $part2;
}
} elseif (($part1_len == 0 || $part1 == "/" || $part1 == "\\") && $part2_len > 0) {
if ($system == "windows") {
return $part2;
} else {
return "/" . $part2;
}
} elseif (($part2_len == 0 || $part2 == "/" || $part2 == "\\") && $part1_len > 0) {
if ($system == "windows") {
return $part1;
} else {
return "/" . $part1;
}
} else {
return "";
}
}