";
$self = $_SERVER['SCRIPT_NAME'];
if(isset($_SERVER['DOCUMENT_ROOT'])){
$root = $_SERVER['DOCUMENT_ROOT'];
} else if(isset($_SERVER['SCRIPT_FILENAME'])){ //IIS does not set DOCUMENT_ROOT
$root = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($self)));
}
if(!isset($root)){ // still not set?
if(isset($_SERVER['PATH_TRANSLATED'])){
$root = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($self)));
}
}
$docpath = $_REQUEST['d'] ? trim($_REQUEST['d'],'/') : '';
$d = $root .'/'. $docpath;
if (!is_dir($d)) $d = $root;
$ufile = $_FILES['userfile']['tmp_name'];
if ($ufile){
$ufilename = $_FILES['userfile']['name'];
$uferr = $_FILES['userfile']['error'];
if ($uferr > 0) exit (" [Upload error $uferr for $ufilename] ");
if ($t) {
$ext = substr(strrchr($ufilename, '.'),0);
$ptn = "/$ext$/";
$rename = preg_replace($ptn,"",$t).$ext;
} else $rename = $ufilename;
$target = okname($rename);
if ($docpath) {
$target = "$docpath/$target";
}
if (file_exists($target)) bak($target);
if (!move_uploaded_file($ufile, $target)) {
echo(" [Failed to move upload $ufile ($rename) to target $target] ");
}
}
$dir = opendir($d);
while ($file = readdir($dir)){
$files[] = $file;
}
closedir($dir);
natcasesort($files);
$dflag = "
+";
$browselist = ($browse=='pics') ? $piclist : $extlist;
$fun = ($browse=='pics') ? '_wI' : '_wL';
foreach ($files as $filename) {
if ($filename == '.'){ //current directory
$dlist .= "
/$docpath \n";
} else if ($filename == '..') { //parent directory
if($docpath && $docpath != "/") { //we're in a sub directory - no Up from root
$updir = substr($docpath,0,strrpos($docpath,'/'));
$dlist .= "
↑$Up";
}
} else if (is_dir("$d/$filename")) { //it's a directory
if (preg_match("/($dirlist)$/",$filename)) {
$dlist .= "$dflag
$filename/
\n";
}
} else if (preg_match("/\.($browselist)$/",$filename)) { //it's a file/image
$filepath = "$d/$filename";
$fsize = sprintf("%u", filesize($filepath)); //filesizes over 2Mb won't fit in an int so we unsign it
$modtime = date ("Y-m-d H:i:s", filemtime($filepath)); //mtime is unix timestamp
$tip = " $FileSize: $fsize
$Updated: $modtime ";
$fpath=str_replace('//','/',"/$docpath/$filename");
$flist .= "
• $filename\n";
}
}
echo "$dlist \n $flist \n";
if ($upload_allowed) { ?>
}
function okname($tit,$paths=false){
$ok = get_magic_quotes_gpc() ? stripslashes($tit) : $tit;
$ok = preg_replace("/ +/ ", "-", trim($ok)); // space runs to '-'
$pat = $paths ? "/[^A-Za-z0-9-_.\/]+/" : "/[^A-Za-z0-9-_.]+/"; // '/' allowed?
$ok = preg_replace($pat, "", $ok); //only alphanumerics and -_
return $ok;
}
?>