task.php
上传用户:yttaitong
上传日期:2009-05-10
资源大小:128k
文件大小:19k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

PHP

  1. <?php
  2. /*
  3.     [BBWPS!] (C)2006-2010 小蜜蜂版权所有.
  4. This is NOT a freeware, use is subject to license terms
  5.     时间:2007年12月
  6.     描述:
  7. */
  8. define('IN_SELF', 'task');
  9. require_once ("./global.php");
  10. session_start();
  11. require_once ($T_function);
  12. $path       = urldecode($_POST['path']);
  13. $parentpath = urlencode(direction($path));
  14. $realpath   = truepath($path);
  15. if($_GET['type']==folder){
  16. $realpath = truepath($path,2);
  17. }
  18. $zippath    = $T_zipdir.'/'.str_replace('/','_',$path);
  19. $reload     = "window.location=('".$T_main."?path=".$parentpath."')";
  20. $sreload    = "window.location=('".$T_main."?path=".$_POST['path']."')";
  21. $preload    = "parent.location=('".$T_main."?path=".$parentpath."')";
  22. $rreload    = "parent.location=('".$T_main."?path=".$_POST['path']."')";
  23. $window     = true;
  24. require_once ($T_language);
  25. if($_POST['action']){
  26. switch($_POST['action']){
  27. case "shortcut":
  28. include_once("shortcut.list");
  29. if(in_array($_POST['path'],(array)$shortcuts)){
  30. echo "<script>alert('快捷方式已存在');</script>";
  31. exit();
  32. }
  33. $i=0;
  34. $shortcuts[]=$_POST['path'];
  35. $handle=fopen("shortcut.list","w");
  36. $str="<?php
  37. ";
  38. foreach($shortcuts as $value){
  39. $str.="$shortcuts[".($i++)."]="".$value."";
  40. ";
  41. }
  42. $str.="?>";
  43. fwrite($handle,$str);
  44. fclose($handle);
  45. echo "<script>alert('创建成功');</script>";
  46. break;
  47. case "replace"://字符串替换
  48. include_once("manager/include/replace.php");
  49. $arrConfig['isReg']         = $_POST['isReg']?1:0;
  50. $arrConfig['sub']           = $_POST['sub']?1:0;
  51. $arrConfig['replacePath']  = $realpath."/";
  52. $arrConfig['fileType']   = explode(",",$_POST['filetype']);
  53. $arrConfig['search'][0]   = $_POST['key'];
  54. $arrConfig['replace'][0] = $_POST['keynew'];
  55. $str = new ReplaceFile($arrConfig);
  56. $content="<div  style="width:100%;height:200;overflow-x:hidden;overflow-y:scroll;"><table><tr><td>&nbsp;&nbsp;&nbsp;</td><td align="left">$str->msg</td></tr></table></div>";
  57. $title="字符串替换";
  58. break;
  59. case "rename"://重命名文件夹或文件之前的检查
  60. $title   = $T_lang['title'][0];
  61. $name = basename($path);
  62. if(checkcore($path)){
  63. $content = $T_lang['rename'][0].$T_lang['confirm'][0];
  64. }else{
  65. $content = $T_lang['rename'][1].$T_lang['form'][0].$T_lang['path'][0].
  66. $T_lang['action'][0].str_replace("--name--",$name,$T_lang['rename'][2]).
  67. $T_lang['submit'][0].$T_lang['cancel'][0].$T_lang['form']['end'];
  68. }
  69. break;
  70. case "truerename"://重命名文件夹或文件
  71. $title   = $T_lang['title'][0];
  72. if($_POST['newname']===""){//判断文件夹或文件名有没有给
  73. $content = $T_lang['newfolder'][0].$T_lang['confirm'][0];
  74. }else{
  75. $newname = $_POST['newname'];
  76. if(file_exists(dirname($realpath)."/".$newname)){
  77. $content = $T_lang['rename'][3].$T_lang['confirm'][0];
  78. }else{
  79. if(rename($realpath,dirname($realpath)."/".$newname)){
  80. $window = false;
  81. $method = $preload;
  82. }else{
  83. $content = $T_lang['rename'][4].$T_lang['confirm'][0];
  84. }
  85. }
  86. }
  87. break;
  88. case "newfolder"://新文件夹
  89. $title   = $T_lang['title'][1];
  90. if($_POST['foldername']===""){//判断文件夹名有没有给
  91. $content = $T_lang['newfolder'][0].$T_lang['confirm'][0];
  92. }else{
  93. $name = $_POST['foldername'];
  94. if(is_dir($realpath."/".$name)){
  95. $content = $T_lang['newfolder'][1].$T_lang['confirm'][0];
  96. }else{
  97. if(@mkdir($realpath."/".$name,0777)){
  98. $window = false;
  99. $method = $rreload;
  100. }else{
  101. $content = $T_lang['newfolder'][2].$T_lang['confirm'][0];
  102. }
  103. }
  104. }
  105. break;
  106. case "newfile"://新文件
  107. $title = $T_lang['title'][2];
  108. $name  = $_POST['filename'].".".$_POST['exttype'];
  109. if($_POST['filename']===""){//判断文件名有没有给
  110. $content = $T_lang['newfile'][0].$T_lang['confirm'][0];
  111. }elseif(file_exists($realpath."/".$name)){
  112. $content = $T_lang['newfile'][1].$T_lang['confirm'][0];
  113. }else{
  114. if(file_exists($T_newfile)){
  115. if(copy($T_newfile,$realpath."/".$name)){
  116. $window = false;
  117. $method = $rreload;
  118. }elseif($fp = fopen($realpath."/".$name,"w")){
  119. flock($fp,LOCK_EX);
  120. fwrite($fp,"newfile",1024);
  121. flock($fp,LOCK_UN);
  122. fclose($fp);
  123. $window = false;
  124. $method = $rreload;
  125. }else{
  126. $content = $T_lang['newfile'][2].$T_lang['confirm'][0];
  127. }
  128. }elseif($fp = fopen($realpath."/".$name,"w")){
  129. flock($fp,LOCK_EX);
  130. fwrite($fp,"newfile",1024);
  131. flock($fp,LOCK_UN);
  132. fclose($fp);
  133. $window = false;
  134. $method = $rreload;
  135. }else{
  136. $content = $T_lang['newfile'][3].$T_lang['confirm'][0];
  137. }
  138. }
  139. break;
  140. case "download"://下载文件或文件夹前的准备
  141.   $title   = $T_lang['title'][3];
  142. if(is_dir($realpath)){//压缩要下载的文件夹
  143. $zip = new ZipAllFloder();
  144. $zip->ZipFolder($realpath,$zippath.".zip");
  145. $content = $T_lang['download'][0].$T_lang['form'][2].$T_lang['action'][1].
  146. $T_lang['path'][1].$T_lang['submit'][1].$T_lang['cancel'][1].
  147. $T_lang['form']['end'];
  148. }else{//检查是否存在文件
  149. if(file_exists($realpath)){
  150. $content = $T_lang['download'][1].$T_lang['form'][1].
  151. $T_lang['action'][1].$T_lang['path'][0].$T_lang['submit'][1].
  152. $T_lang['cancel'][1].$T_lang['form']['end'];
  153. }else{
  154. $content = $T_lang['download'][2].$T_lang['confirm'][0];
  155. }
  156. }
  157. break;
  158. case "truedownload"://直接下载文件
  159. $filename = basename($path);
  160. $str='Content-Disposition: attachment; filename="'.$filename.'"';
  161. header("Content-type: application/force-download");
  162. header($str);
  163. readfile($realpath);
  164. exit;
  165. break;
  166. case "crush"://回收文件或文件夹前的检查
  167. $title   = $T_lang['title'][4];
  168. if(checkcore($path)){//检查核心文件是否是该$path的一个节点
  169. $content = $T_lang['crush'][0].$T_lang['confirm'][0];
  170. }else{
  171. $content = $T_lang['crush'][1].$T_lang['form'][0].$T_lang['path'][0].
  172. $T_lang['action'][2].$T_lang['submit'][2].$T_lang['cancel'][0].
  173. $T_lang['form']['end'];
  174. }
  175. break;
  176. case "back"://删除文件或文件夹
  177. $title   = $T_lang['title'][4];
  178. $from    = $T_fprefix.base64_encode(direction($path)).$T_fsuffix;
  179. if(is_dir($realpath)){
  180. $target = $T_Recycled."/".basename($path).$T_tprefix.date('Y-m-d H-i-s').
  181. $T_tsuffix.$from;
  182. $return = movepath($realpath,$target);
  183. if($return){
  184. $content = str_replace("--alert--",$return,$T_lang['font'][0]).
  185. $T_lang['confirm'][1];
  186. }else{
  187. $content = $T_lang['back'][0].$T_lang['confirm'][1];
  188. }
  189. }else{
  190. if($suffix=fileext(basename($realpath))){
  191. $suffix = ".".$suffix;
  192. $target = $T_Recycled."/".basename($path,$suffix).$T_tprefix.
  193. date('Y-m-d H-i-s').$T_tsuffix.$from.$suffix;
  194. }else{
  195. $target = $T_Recycled."/".basename($path).$T_tprefix.
  196. date('Y-m-d H-i-s').$T_tsuffix.$from;
  197. }
  198. if(@copy($realpath,$target)){
  199. @unlink($realpath);
  200. $content = $T_lang['back'][1].$T_lang['confirm'][1];
  201. }else{
  202. $content = $T_lang['back'][2].$T_lang['confirm'][0];
  203. }
  204. }
  205. break;
  206. case "return"://还原回收站内的文件或文件夹
  207. $title   = $T_lang['title'][5];
  208. if(ereg(".*".$T_fprefix_."(.*)".$T_fsuffix_.".*",$path)){
  209. $return = ereg_replace(".*".$T_fprefix_."(.*)".$T_fsuffix_.".*",
  210. "\1",$path);
  211. $return = truepath(base64_decode($return));
  212. if(is_dir($realpath)){
  213. $target = $return."/".ereg_replace("(.*)".$T_tprefix_.".*","\1",
  214. basename($path));
  215. if($errors = movepath($realpath,$target)){
  216. $content = str_replace("--alert--",$errors,$T_lang['font'][0]).
  217. $T_lang['confirm'][0];
  218. }else{
  219. $window = false;
  220. $method = $preload;
  221. }
  222. }else{
  223. $target = $return."/".
  224. ereg_replace("(.*)".$T_tprefix_.".*".$T_tsuffix_."(..*)?","\1\2",
  225. basename($path));
  226. if(file_exists($target)){
  227. $content = $T_lang['return'][0].$T_lang['confirm'][0];
  228. }else{
  229. if(@copy($realpath,$target)){
  230. if(@unlink($realpath)){
  231. $window = false;
  232. $method = $preload;
  233. }else{
  234. $content = $T_lang['return'][1].$T_lang['confirm'][0];
  235. }
  236. }
  237. }
  238. }
  239. }else{
  240. $content = $T_lang['return'][2].$T_lang['confirm'][0];
  241. }
  242. break;
  243. case "delete"://删除文件夹或文件前的confirm
  244. $title   = $T_lang['title'][6];
  245. if(checkcore($path)){
  246. $content = $T_lang['delete'][0].$T_lang['confirm'][0];
  247. }else{
  248. $content = $T_lang['delete'][1].$T_lang['form'][0].$T_lang['action'][3].
  249. $T_lang['path'][0].$T_lang['submit'][3].$T_lang['cancel'][0].
  250. $T_lang['form']['end'];
  251. }
  252. break;
  253. case "truedelete"://删除文件夹或文件
  254. $title   = $T_lang['title'][6];
  255. if(file_exists($realpath)){
  256. if(is_dir($realpath)){//删除整个文件夹
  257. $return = delpath($realpath);
  258. if($return){
  259. $content = str_replace("--alert--",$return,$T_lang['font'][0]).
  260. $T_lang['confirm'][1];
  261. }else{
  262. $content = $T_lang['delete'][2].$T_lang['confirm'][1];
  263. }
  264. }else{//删除单个文件
  265. if(@unlink($realpath)){
  266. $content = $T_lang['delete'][3].$T_lang['confirm'][1];
  267. }else{
  268. $content = $T_lang['delete'][4].$T_lang['confirm'][1];
  269. }
  270. }
  271. }else{
  272. $content = $T_lang['delete'][5].$T_lang['confirm'][1];
  273. }
  274. break;
  275. case "scissor"://创建剪切任务
  276. if(checkcore($path)){
  277. $title   = $T_lang['title'][7];
  278. $content = $T_lang['scissor'][0].$T_lang['confirm'][0];
  279. }else{
  280. if(isset($_SESSION['readystick'])){
  281. unset($_SESSION['readystick']);
  282. }
  283. $_SESSION['readystick'][0] = $_POST['path'];
  284. $_SESSION['readystick'][1] = "scissor";
  285. $window = false;
  286. $method = NULL;
  287. }
  288. break;
  289. case "copy"://创建拷贝任务
  290. if(isset($_SESSION['readystick'])){
  291. unset($_SESSION['readystick']);
  292. }
  293. $_SESSION['readystick'][0] = $_POST['path'];
  294. $_SESSION['readystick'][1] = "copy";
  295. $window = false;
  296. $method = NULL;
  297. break;
  298. case "stepstick"://粘贴前的检查
  299. $break = true;
  300. $title = $T_lang['title'][8];
  301. if(isset($_SESSION['readystick'])){
  302. $source = truepath(urldecode($_SESSION['readystick'][0]));
  303. if(is_dir($realpath."/".basename($source))&&is_dir($source)&&
  304. (strtolower(dirname($source))!=strtolower($realpath)))
  305. {
  306. $content = str_replace("--target--",$path."/".basename($source),
  307. $T_lang['stick'][0]).$T_lang['submit'][4].$T_lang['cancel'][0];
  308. }elseif(file_exists($realpath."/".basename($source))&&is_file($source)&&
  309. (strtolower(dirname($source))!=strtolower($realpath)))
  310. {
  311. $content = str_replace("--target--",$path."/".basename($source),
  312. $T_lang['stick'][1]).$T_lang['submit'][4].$T_lang['cancel'][0];
  313. }else{
  314. $break = false;
  315. }
  316. }else{
  317. $content = $T_lang['stick'][3].$T_lang['confirm'][0];
  318. }
  319. if($break){
  320. break;
  321. }
  322. case "stick"://开始粘贴
  323. $title   = $T_lang['title'][8];
  324. if(isset($_SESSION['readystick'])){
  325. $source = truepath(urldecode($_SESSION['readystick'][0]));
  326. if($_SESSION['readystick'][1] == "copy"){//粘贴拷贝任务
  327. if(strtolower(dirname($source)) == strtolower($realpath)){
  328. $target = $path."/".$T_lang['stick'][4].basename($source);
  329. }else{
  330. $target = $path."/".basename($source);
  331. }
  332. if(checkcore($target)){
  333. $errors = $T_lang['stick'][5];
  334. }else{
  335. $target = truepath($target);
  336. if(is_dir($source)){
  337. if($_POST['type']=="cover"){
  338. $errors = copypath($source,$target,false);
  339. }else{
  340. $errors = copypath($source,$target);
  341. }
  342. if($errors==""){
  343. $errors = $T_lang['stick'][6];
  344. }else{
  345. $errors = str_replace("--alert--",$errors,
  346. $T_lang['font'][0]);
  347. }
  348. }else{
  349. if(@copy($source,$target)){
  350. $errors = $T_lang['stick'][7];
  351. }else{
  352. $errors = str_replace("--source--",$source,
  353. $T_lang['stick'][8]);
  354. }
  355. }
  356. }
  357. }elseif($_SESSION['readystick'][1] == "scissor"){//粘贴剪切任务
  358. if(strtolower(dirname($source)) == strtolower($realpath)){
  359. $errors = $T_lang['stick'][9];
  360. }else{
  361. $target = $path."/".basename($source);
  362. if(checkcore($target)){
  363. $errors = $T_lang['stick'][10];
  364. }else{
  365. $target = truepath($target);
  366. if(is_dir($source)){
  367. if($_POST['type']=="cover"){
  368. $errors = movepath($source,$target,false);
  369. }else{
  370. $errors = movepath($source,$target);
  371. }
  372. if($errors==""){
  373. $errors = $T_lang['stick'][11];
  374. }else{
  375. $errors = str_replace("--alert--",$errors,
  376. $T_lang['font'][0]);
  377. }
  378. }else{
  379. if(@copy($source,$target)){
  380. if(@unlink($source)){
  381. $errors = $T_lang['stick'][12];
  382. }else{
  383. $errors = str_replace("--source--",$source,
  384. $T_lang['stick'][13]);
  385. }
  386. }else{
  387. $errors = str_replace("--source--",$source,
  388. $T_lang['stick'][14]);
  389. }
  390. }
  391. }
  392. }
  393. }
  394. unset($_SESSION['readystick']);
  395. }else{
  396. $errors = $T_lang['stick'][15];
  397. }
  398. $content = $errors.$T_lang['confirm'][2];
  399. break;
  400. case "recycled"://清空回收站任务
  401. $title   = $T_lang['title'][9];
  402. $errors=delpath($T_Recycled);
  403. if($errors==""){
  404. $errors = $T_lang['recycled'][0];
  405. }else{
  406. $errors = str_replace("--alert--",$errors,$T_lang['font'][0]);
  407. }
  408. $content = $errors.$T_lang['confirm'][1];
  409. echo "<script>parent.parent.left.webFXTreeHandler.selected.reload();</script>";
  410. break;
  411. case "attribute"://获得文件或文件夹的信息
  412. $title   = $T_lang['title'][10];
  413. $basename = basename($path);
  414. $position = $path;
  415. if(is_dir($realpath)){
  416. $attribute = new StatFolder($realpath);
  417. $size      = $attribute->GetTotalSize();
  418. $num       = $attribute->GetFileNum();
  419. $typenum   = $attribute->GetTypeNum();
  420. $foldernum = $attribute->GetFolderNum();
  421. $content   = str_replace("--basename--",$basename,$T_lang['attribute'][0]);
  422. $content   = str_replace("--position--",$position,$content);
  423. $content   = str_replace("--size--",$size,$content);
  424. $content   = str_replace("--num--",$num,$content);
  425. $content   = str_replace("--typenum--",$typenum,$content);
  426. $content   = str_replace("--foldernum--",$foldernum,$content);
  427. }else{
  428. $size     = filesize($realpath);//大小
  429. $atime    = date("Y-m-d H:i:s", fileatime($realpath));//修改时间
  430. $mtime    = date("Y-m-d H:i:s", filemtime($realpath));//访问时间
  431. clearstatcache();
  432. $content  = str_replace("--basename--",$basename,$T_lang['attribute'][1]);
  433. $content  = str_replace("--position--",$position,$content);
  434. $content  = str_replace("--size--",$size,$content);
  435. $content  = str_replace("--atime--",$atime,$content);
  436. $content  = str_replace("--mtime--",$mtime,$content);
  437. }
  438. break;
  439. case "upload"://上传文件
  440. $title   = $T_lang['title'][11];
  441. $content = "";
  442. foreach($_FILES["file"]["error"] as $key => $value){
  443. if($_FILES["file"]["name"][$key]!=""){
  444. if($value==UPLOAD_ERR_OK){
  445. $filename = $_FILES["file"]["name"][$key];
  446. if(move_uploaded_file($_FILES["file"]["tmp_name"][$key],
  447. $T_tempdir."/".$filename))
  448. {
  449. if(file_exists($realpath."/".$filename)){
  450. $content.= str_replace("--filename--",$filename,
  451. $T_lang['upload'][0]);
  452. }else{
  453. if(copy($T_tempdir."/".$filename,$realpath."/".$filename)){
  454. @unlink($T_tempdir."/".$filename);
  455. $content .= str_replace("--filename--",$filename,
  456. $T_lang['upload'][1]);
  457. }else{
  458. $content .= str_replace("--filename--",$filename,
  459. $T_lang['upload'][2]);
  460. }
  461. }
  462. }else{
  463. $content .= str_replace("--filename--",$filename,
  464. $T_lang['upload'][2]);
  465. }
  466. }else{
  467. $content .= str_replace("--filename--",$filename,
  468. $T_lang['upload'][2]);
  469. }
  470. }
  471. }
  472. $content.= $T_lang['confirm'][2];
  473. break;
  474. case "rewrite"://编辑文件准备
  475. $title   = $T_lang['title'][13]."[".$path."]";
  476. if(checkcore($path)){
  477. $content = $T_lang['rewrite'][0].$T_lang['confirm'][0];
  478. }else{
  479. if(in_array(fileext($path),$T_editext)){
  480. $txtfile  = $T_task."?action=edit&path=".$_POST['path'];
  481. $editfile = str_replace("--txtfile--",$txtfile,$T_lang['rewrite'][1]);
  482. }else{
  483. $content = $T_lang['rewrite'][2].$T_lang['confirm'][0];
  484. }
  485. }
  486. break;
  487. case "savefile"://保存文件
  488. $txtdata = trim($_POST['txtdata']);
  489. if($txtdata!==""){
  490. if($T_Magic) $txtdata = stripslashes($txtdata);
  491. $txtdata = preg_replace("/[s]textarea/i","textarea",$txtdata);
  492. $txtdata = preg_replace("/[s]xml/i","xml",$txtdata);
  493. $fp = fopen($realpath, 'w');
  494. flock($fp,LOCK_EX);
  495. fwrite($fp,$txtdata);
  496. flock($fp,LOCK_UN);
  497. fclose($fp);
  498. }
  499. header("Location:{$T_task}?action=edit&path=".$_POST['path']);
  500. exit;
  501. break;
  502. default://未定义页面
  503. $title   = $T_lang['title'][15];
  504. $content = $T_lang['undefined'][0].$T_lang['confirm'][0];
  505. break;
  506. }
  507. }elseif($_GET['action']=="edit"&&$_GET['path']){//编辑文件
  508. $path = urldecode($_GET['path']);
  509. $realpath = truepath($path);
  510. $datafile = "";
  511. if(is_file($realpath)&&!checkcore($path)){
  512. if(filesize($realpath)==0){
  513. $datafile = $T_lang['rewrite'][4];
  514. }else{
  515. $fp = fopen($realpath, 'r');
  516. flock($fp,LOCK_SH);
  517. $datafile = fread($fp,filesize($realpath));
  518. flock($fp,LOCK_UN);
  519. fclose($fp);
  520. $datafile = preg_replace("/textarea/i"," textarea",$datafile);
  521. $datafile = preg_replace("/<?xml/i","<? xml",$datafile);
  522. }
  523. }else{
  524. $datafile = str_replace("--filename--",$path,$T_lang['rewrite'][3]);
  525. }
  526. }
  527. if($window){
  528. if($content!=""){
  529. echo "<script type="text/javascript">parent.newwindow('".$title.
  530. "','".$content."');</script>";
  531. exit;
  532. }elseif($datafile!=""){
  533. require_once($T_edit);
  534. exit;
  535. }elseif($editfile!=""){
  536. echo "<script type="text/javascript">parent.editwindow('".$title.
  537. "','".$editfile."');</script>";
  538. exit;
  539. }
  540. }else{
  541. if($method){
  542. echo "<script type="text/javascript">".$method."</script>";
  543. }
  544. }
  545. ?>