Code: Select all
<?php
function doc_root($root_type) {
settype($string_position, "string");
settype($filename, "string");
settype($doc_folder, "string");
//
//Retrieve folder path.
//
if($root_type == "dir_path" or $root_type == "url") {
$i = -1;
while($string_position != "/") {
$string_position = substr($_SERVER['SCRIPT_NAME'], $i, 1);
$filename = $string_position . $filename;
$i--;
}
$path_length = strlen($_SERVER['SCRIPT_NAME']) - strlen($filename);
$doc_folder = substr($_SERVER['SCRIPT_NAME'], 0, $path_length);
} elseif($root_type == "prev_dir_path" or $root_type == "prev_url") {
$i = 1;
$doc_folder = "/";
while($string_position != "/") {
$string_position = substr($_SERVER['SCRIPT_NAME'], $i, 1);
if($string_position != "/") {
$doc_folder .= $string_position;
}
$i++;
}
}
//
//Retrieve and store document path.
//
if($root_type == "url" or $root_type = "prev_url") {
return "http://" . $_SERVER['HTTP_HOST'] . $doc_folder . "/"; //This is what's timing out. Comment this out and it works.
} elseif($root_type == "dir_path" or $root_type == "prev_dir_path") {
return $_SERVER['DOCUMENT_ROOT'] . $doc_folder . "/";
}
}
?>