PHP实用小程序(一)

  1. <?
  2. //设置路径(默认当前php文件所在路径)
  3. $basedir = "d:/inetpub/wwwroot";
  4. $textrows = "20";
  5. $textcols = "85";
  6. if(!$wdir) $wdir="/";
  7. //HTML的标头
  8. function html_header(){
  9. global $basedir;
  10. global $wdir;
  11. global $lastaction;
  12. echo "<HEAD>";
  13. echo "<TITLE>文件目录操作</TITLE>";
  14. echo "</HEAD>";
  15. echo "<BODY bgcolor=\"#fafad2\" link=\"#4C4C99\" vlink=\"#4C4C99\" alink=\"#4C4C99\">";
  16. echo "<table border=\"0\" align=\"center\" cellspacing=\"3\" cellpadding=\"3\" width=\"600\">";
  17. echo "<tr>";
  18. echo "<th colspan=\"2\" width=\"100%\" bgcolor=\"#00bfff\">";
  19. echo "&nbsp;<font size=\"6\" color=\"white\" face=\"arial, helvetica\">文件操作系统</font> &nbsp";
  20. echo "</th>";
  21. echo "</tr>";
  22. echo "<tr>";
  23. echo "<td width\"50%\" align=\"left\"><A HREF=\"$PHP_SELF?action=root\"><font size=\"4\" face=\"arial, helvetica\">回根目录($basedir)</font></a></td>";
  24. echo "<td width\"50%\" align=\"right\"><A HREF=\"$PHP_SELF?wdir=$wdir\" title=\"Refresh current dir\"><font size=\"4\" face=\"arial, helvetica\">$wdir</font><img src=\"explore.gif\" border=\"0\"></a></td>";
  25. echo "</tr>";
  26. echo "<tr>";
  27. echo "<td colspan=\"2\"><hr></td>";
  28. echo "</tr>";
  29. echo "<tr>";
  30. echo " <td colspan=\"2\"><b><font size=\"3\" color=\"#4C4C99\" face=\"arial, helvetica\">$lastaction</font></b></td>";
  31. echo "<tr>";
  32. echo "<td colspan=\"2\"><hr><td>";
  33. echo "</tr>";
  34. echo "<tr>";
  35. echo "<td colspan=\"2\">";
  36. }
  37. //计算文件大小
  38. function display_size($file){
  39. $file_size = filesize($file);
  40. if($file_size >= 1073741824)
  41. {
  42. $file_size = round($file_size / 1073741824 * 100) / 100 . "g";
  43. }
  44. elseif($file_size >= 1048576)
  45. {
  46. $file_size = round($file_size / 1048576 * 100) / 100 . "m";
  47. }
  48. elseif($file_size >= 1024)
  49. {
  50. $file_size = round($file_size / 1024 * 100) / 100 . "k";
  51. }
  52. else{
  53. $file_size = $file_size . "b";
  54. }
  55. return $file_size;
  56. }
  57. //文件列表函数
  58. function displaydir()
  59. {
  60. global $basedir;
  61. global $wdir;
  62. //Table标题
  63. echo "<TABLE BORDER=\"0\" cellspacing=\"1\" cellpadding=\"1\" width=\"100%\">";
  64. echo "<tr>";
  65. echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">类型</font></th>";
  66. echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">名称</font></th>";
  67. echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">大小</font></th>";
  68. echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">修改时间</font></th>";
  69. echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">属性</font></th>";
  70. echo "<th bgcolor=\"#b0c4de\"><font color=\"white\" face=\"arial, helvetica\">操作</font></th>";
  71. echo "</tr>";
  72. //将子目录和文件存放在数组中
  73. //echo $basedir . $wdir;
  74. chdir($basedir . $wdir);
  75. $handle=opendir(".");
  76. while ($file = readdir($handle))
  77. {
  78. if(is_dir($file)) $dirlist[] = $file;
  79. if(is_file($file)) $filelist[] = $file;
  80. }
  81. closedir($handle);
  82. //首先存放子目录
  83. if($dirlist)
  84. {
  85. //目录排序
  86. asort($dirlist);
  87. //遍厉数组
  88. while (list ($key, $file) = each ($dirlist))
  89. {
  90. //
  91. if (!($file == "."))
  92. {
  93. $filename=$basedir.$wdir.$file;
  94. $fileurl=rawurlencode($wdir.$file);
  95. $lastchanged = filectime($filename);
  96. $changeddate = date("d-m-Y H:i:s", $lastchanged);
  97. echo "<TR>";
  98.  
  99. //建立回上一级目录的箭头
  100. if($file == "..")
  101. {
  102. $downdir = dirname("$wdir");
  103. echo "<TD align=\"center\" nobreak><A HREF=\"$PHP_SELF?action=chdr&file=$downdir\"><img src=\"parent.gif\" alt=\"Parent directory\" border=\"0\"></a></TD>\n";
  104. echo "<TD></TD>\n";
  105. echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . display_size($filename) . "</font></TD>";
  106. echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . $changeddate . "</font></TD><TD align=\"right\">";
  107. printf("%o", (fileperms($filename)) & 0777);
  108. echo "</TD><TD nobreak>";
  109. echo "<A HREF=\"$PHP_SELF?action=chdr&file=$downdir\"><img src=\"parent.gif\" alt=\"Parent directory\" border=\"0\"></A> ";
  110. }
  111. //列出目录
  112. else
  113. {
  114. $lastchanged = filectime($filename);
  115. echo "<TD align=\"center\" nobreak><A HREF=\"$PHP_SELF?action=chdr&file=$fileurl\"><img src=\"folder.gif\" alt=\"$basedir$file\" border=\"0\"></a></TD>\n";
  116. echo "<TD nobreak><font size =\"-1\" face=\"arial, helvetica\">" . htmlspecialchars($file) . "</font></TD>\n";
  117. echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . display_size($filename) . "</font></TD>";
  118. echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . $changeddate . "</font></TD><TD align=\"right\">";
  119. echo "<A HREF=\"$PHP_SELF?action=chmod&file=$filename\"><font size =\"-1\" face=\"arial, helvetica\">";
  120. printf("%o", (fileperms($filename)) & 0777);
  121. echo "</A>";
  122. echo "</font></TD><TD nobreak>";
  123. echo " <A HREF=\"$PHP_SELF?action=move&wdir=$wdir&file=$fileurl\"><img src=\"move.gif\" alt=\"Move,rename or copy $file\" border=\"0\"></A> ";
  124. echo " <A HREF=\"$PHP_SELF?action=touch&wdir=$wdir&touchfile=$fileurl\"><img src=\"touch.gif\" alt=\"Touch $file\" border=\"0\"></A> ";
  125. echo "<A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$fileurl\"><img src=\"delete.gif\" alt=\"Delete $file\" border=\"0\"></A> ";
  126. }
  127. }
  128. }
  129. }
  130. //列出文件
  131. if($filelist)
  132. {
  133. //文件排序
  134. asort($filelist);
  135. while (list ($key, $file) = each ($filelist))
  136. {
  137. //检查文件格式并显示相应的图表和属性
  138. //图片文件
  139. if (ereg(".gif|.jpg",$file))
  140. {
  141. $icon = "<IMG SRC=\"image.gif\" alt=\"Image\" border=\"0\">";
  142. $browse = "1";
  143. $raw = "0";
  144. $image = "1";
  145. }
  146. //文本文件
  147. elseif (ereg(".txt",$file))
  148. {
  149. $icon = "<IMG SRC=\"text.gif\" alt=\"Text\" border=\"0\">";
  150. $browse = "1";
  151. $raw = "1";
  152. $image = "0";
  153. }
  154. //音频文件
  155. elseif (ereg(".wav|.mp2|.mp3|.mp4|.vqf|.midi",$file))
  156. {
  157. $icon = "<IMG SRC=\"audio.gif\" alt=\"Audio\" border=\"0\">";
  158. $browse = "1";
  159. $raw = "0";
  160. $image = "0";
  161. }
  162. //Web服务器文件
  163. elseif (ereg(".phps|.php|.php2|.php3|.php4|.asp|.asa|.cgi|.pl|.shtml",$file))
  164. {
  165. $icon = "<IMG SRC=\"webscript.gif\" alt=\"Web program\" border=\"0\">";
  166. $browse = "1";
  167. $raw = "1";
  168. $image = "0";
  169. }
  170. //Apache Web服务器安全设置
  171. elseif (ereg(".htaccess",$file))
  172. {
  173. $icon = "<IMG SRC=\"security.gif\" alt=\"Apache Webserver security settings\" border=\"0\">" ;
  174. $browse = "0";
  175. $raw = "1";
  176. $image = "0";
  177. }
  178. //Web页面文件
  179. elseif (ereg(".html|.htm",$file))
  180. {
  181. $icon = "<IMG SRC=\"webpage.gif\" alt=\"Web page\" border=\"0\">";
  182. $browse = "1";
  183. $raw = "1";
  184. $image = "0";
  185. }
  186. //不确定格式文件
  187. else
  188. {
  189. $icon = "<IMG SRC=\"text.gif\" alt=\"Unknown filetype\" border=\"0\">";
  190. $browse = "1";
  191. $raw = "1";
  192. $image = "0";
  193. }
  194. //文件列表
  195. $filename=$basedir.$wdir.$file;
  196. $fileurl=rawurlencode($wdir.$file);
  197. $lastchanged = filectime($filename);
  198. $changeddate = date("d-m-Y H:i:s", $lastchanged);
  199. echo "<TR>";
  200. echo "<TD align=\"center\" nobreak>";
  201. //产生文件图标以便预览
  202. if($raw == "1")
  203. {
  204. echo "<A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl\">";
  205. }
  206. if($image == "1")
  207. {
  208. echo "<A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&image=$image\">";
  209. }
  210. echo "$icon</TD>\n";
  211. echo "<TD nobreak><font size =\"-1\" face=\"arial, helvetica\">" . htmlspecialchars($file) . "</font></TD>\n";
  212. echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . display_size($filename) . "</font></TD>";
  213. echo "<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, helvetica\">" . $changeddate . "</font></TD><TD align=\"right\">";
  214. echo "<A HREF=\"$PHP_SELF?action=chmod&wdir=$wdir&file=$fileurl\" title=\"Change permission level on $file\"><font size =\"-1\" face=\"arial, helvetica\">";
  215. printf("%o", (fileperms($filename)) & 0777);
  216. echo "</font></A>";
  217. echo "</TD><TD nobreak>";
  218. echo " <A HREF=\"$PHP_SELF?action=move&wdir=$wdir&file=$fileurl\"><img src=\"move.gif\" alt=\"Move,rename or copy $file\" border=\"0\"></A> ";
  219. echo " <A HREF=\"$PHP_SELF?action=touch&wdir=$wdir&touchfile=$fileurl\"><img src=\"touch.gif\" alt=\"Touch $file\" border=\"0\"></A> ";
  220. echo "<A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$fileurl\"><img src=\"delete.gif\" alt=\"Delete $file\" border=\"0\"></A> ";
  221. //如果文件可以浏览,则给出浏览图标
  222. if($browse == "1")
  223. {
  224. echo " <A HREF=\"$wdir$file\"><img src=\"browse.gif\" alt=\"Browse\" border=\"0\"></A> ";
  225. }
  226. //如果文件可以编辑,则给出编辑图标
  227. if($raw =="1")
  228. {
  229. echo " <A HREF=\"$PHP_SELF?wdir=$wdir&action=edit&file=$fileurl\"><img src=\"edit.gif\" alt=\"Edit\" border=\"0\"></A> ";
  230. }
  231. }
  232. }
  233. echo "</TD></TR>\n";
  234. echo "</TABLE>";
  235. //显示出不同提交的Form表
  236. echo "<table border=\"0\" width=\"100%\">";
  237. echo "<TR><TD colspan=\"2\"><hr></td>";
  238. //文件上传
  239. echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">上传文件</font></td><td>";
  240. echo "<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
  241. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
  242. echo "<INPUT NAME=\"userfile\" TYPE=\"file\" size=\"40\">";
  243. echo "<INPUT TYPE=\"SUBMIT\" NAME=\"upload\" VALUE=\"Go!\"></TD></TR>";
  244. echo "</FORM>";
  245. //创建新目录
  246. echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
  247. echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">创建目录</font></td><td>";
  248. echo "<INPUT TYPE=\"TEXT\" NAME=\"mkdirfile\" size=\"40\">";
  249. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"mkdir\">";
  250. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
  251. echo "<INPUT TYPE=\"SUBMIT\" NAME=\"mkdir\" VALUE=\"Go!\"></TD></TR>";
  252. echo "</FORM>";
  253. //产生新文件
  254. echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">";
  255. echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">新建文件</font></td><td>";
  256. echo "<INPUT TYPE=\"TEXT\" NAME=\"file\" size=\"40\">";
  257. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"createfile\"> ";
  258. echo "<input type=\"checkbox\" name=\"html\" value=\"yes\"><font size =\"-2\" face=\"arial, helvetica\">(html template)</font> ";
  259. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
  260. echo "<INPUT TYPE=\"SUBMIT\" NAME=\"createfile\" VALUE=\"Go!\">";
  261. echo "</TD></TR>";
  262. echo "</TABLE>";
  263. echo "</FORM>";
  264. }
  265. //用户点击CANCEL,取消提交
  266. if($cancel) $action="";
  267. //上传文件处理
  268. if($upload)
  269. {
  270. copy($userfile,$basedir.$wdir.$userfile_name);
  271. $lastaction = "上传文件到 $basedir$wdir";
  272. html_header();
  273. displaydir();
  274. echo $html_ender;
  275. exit;
  276. }
  277. ################################################################################
  278. //开始处理actions
  279. switch ($action)
  280. {
  281. //没有$action变量则显示初始页面
  282. case "":
  283. $lastaction = "$basedir";
  284. html_header();
  285. displaydir();
  286. echo $html_ender;
  287. break;
  288. //回根目录
  289. case "root":
  290. $wdir="/";
  291. $lastaction = "$basedir";
  292. html_header();
  293. displaydir();
  294. echo $html_ender;
  295. break;
  296. //改变目录
  297. case "chdr":
  298. $wdir=$file."/";
  299. $lastaction = "$basedir$wdir";
  300. html_header();
  301. displaydir();
  302. echo $html_ender;
  303. break;
  304. // 改动的对象
  305. case "touch":
  306. touch($basedir.$touchfile);
  307. $lastaction = "Touched $touchfile";
  308. html_header();
  309. displaydir();
  310. echo $html_ender;
  311. break;
  312. //调试报表
  313. case "bugreport":
  314. if ($send)
  315. {
  316. $lastaction = "Bug reported. Thank you!";
  317. html_header();
  318. mail("president@suneworld.com","Bug report","Name: $name \nVersion: $version \n\nProblem: $problem");
  319. echo "<h3><a href=\"$PHP_SELF?action=help&wdir=$wdir\">Back to help</a></h3>";
  320. }
  321. else
  322. {
  323. $lastaction = "Bug report form";
  324. html_header();
  325. ?>
  326. <table>
  327. <form action="<? echo "$PHP_SELF?action=bugreport&wdir=$wdir&send=1"; ?>" method="POST">
  328. <tr>
  329. <td>Your name:</td>
  330. <td><input name="name" size="24" maxlength="30"></td>
  331. </tr><tr>
  332. <td>Your email adress:</td>
  333. <td><input name="email" size="24" maxlength="30"></td>
  334. </tr><tr>
  335. <td>Description of problem(s):</td>
  336. <td><textarea name="problem" cols="30" rows="5"></textarea></td>
  337. </tr><tr>
  338. <td colspan="2" align="center"><input type="submit" value="Send"></td>
  339. </tr>
  340. </table>
  341. <?
  342. }
  343. echo $html_ender;
  344. break;
  345. //删除文件或目录
  346. case "del":
  347. //用户确认删除
  348. if ($confirm)
  349. {
  350.  
  351. //删除对象是目录
  352. if(is_dir($basedir.$file))
  353. {
  354. rmdir($basedir.$file);
  355. }
  356. //删除对象是文件
  357. else
  358. {
  359. exec("delete $basedir.$file");
  360. //unlink($basedir.$file);
  361. }
  362. $lastaction = "删除 $file";
  363. html_header();
  364. displaydir();
  365. }
  366. //显示删除提示
  367. else
  368. {
  369. $lastaction = "确实要删除<br>$file吗?";
  370. html_header();
  371. echo "<center><b><font size =\"5\" face=\"arial, helvetica\"><A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$file&confirm=1\">YES!</A></font><br>";
  372. echo "<p><font size =\"5\" face=\"arial, helvetica\"><A HREF=\"$PHP_SELF?wdir=$wdir\">NO!</A></font><br><b></center>";
  373. }
  374. echo $html_ender;
  375. break;
  376. //改变权限属性
  377. case "chmod":
  378. //用户确认
  379. if ($confirm)
  380. {
  381. $level = "0";
  382. $level .= $owner;
  383. $level .= $group;
  384. $level .= $public;
  385. $showlevel = $level;
  386. $level=octdec($level);
  387. chmod($basedir.$file,$level);
  388. $lastaction = "改变属性 $file to $showlevel";
  389. html_header();
  390. displaydir();
  391. }
  392. //提示
  393. else
  394. {
  395. $lastaction = "改变属性$file";
  396. html_header();
  397. echo "<font face=\"arial, helvetica\"><center><h4>Current level: ";
  398. printf("%o", (fileperms($basedir.$file)) & 0777);
  399. echo "</h4><FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
  400. function selections()
  401. {
  402. echo "<option value=\"0\">0 - No permissions";
  403. echo "<option value=\"1\">1 - Execute";
  404. echo "<option value=\"2\">2 - Write ";
  405. echo "<option value=\"3\">3 - Execute & Write";
  406. echo "<option value=\"4\">4 - Read";
  407. echo "<option value=\"5\">5 - Execute & Read";
  408. echo "<option value=\"6\">6 - Write & Read";
  409. echo "<option value=\"7\">7 - Write, Execute & Read";
  410. echo "</select>";
  411. }
  412. echo "<p><h4>Owner<br>";
  413. echo "<select name=\"owner\">";
  414. selections();
  415. echo "<p>Group<br>";
  416. echo "<select name=\"group\">";
  417. selections();
  418. echo "<p>Public<br>";
  419. echo "<select name=\"public\">";
  420. selections();
  421. echo "</h4>";
  422. echo "<p>";
  423. echo "<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Change\">\n";
  424. echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Cancel\">\n";
  425. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"chmod\">\n";
  426. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">";
  427. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">";
  428. echo "</FORM>";
  429. echo "</center>";
  430. }
  431. echo $html_ender;
  432. break;
  433. //移动文件
  434. case "move":
  435. //用户确认对象重命名、移动或复制
  436. if($confirm && $newfile)
  437. {
  438. //对象存在
  439. if(file_exists($basedir.$newfile))
  440. {
  441. $lastaction = "Destination file already exists. Aborted.";
  442. }
  443. else
  444. {
  445. if($do == copy)
  446. {
  447. copy($basedir.$file,$basedir.$newfile);
  448. $lastaction = "Copied\n$file to $newfile";
  449. }
  450. else
  451. {
  452. rename($basedir.$file,$basedir.$newfile);
  453. $lastaction = "Moved/renamed\n$file to $newfile";
  454. }
  455. }
  456. html_header();
  457. displaydir();
  458. echo $html_ender;
  459. }
  460. //提示
  461. else
  462. {
  463. $lastaction = "Moving/renaming or copying<br>$file";
  464. html_header();
  465. echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
  466. echo "<select name=\"do\">";
  467. echo "<option value=\"copy\">Copy";
  468. echo "<option value=\"move\">Move/rename";
  469. echo "</select> ";
  470. echo "($file)";
  471. echo "<h4>To</h4>";
  472. echo "<INPUT TYPE=\"TEXT\" NAME=\"newfile\" value=\"$file\" size=\"40\">\n";
  473. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n";
  474. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"move\">\n";
  475. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
  476. echo "<p>";
  477. echo "<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Do\">\n";
  478. echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Cancel\">\n";
  479. echo "</FORM>";
  480. echo $html_ender;
  481. }
  482. break;
  483. //编辑文件
  484. case "edit":
  485.  
  486. //用户编辑完毕,返回主页面
  487. if($confirm && $file)
  488. {
  489. $lastaction = "Edited $file";
  490. html_header();
  491. $fp=fopen($basedir.$file,"w");
  492. fputs($fp,stripslashes($code));
  493. fclose($fp);
  494. displaydir();
  495. }
  496. //在textarea显示文件内容
  497. else
  498. {
  499. $lastaction = "Editing $file";
  500. html_header();
  501. echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
  502. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
  503. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"edit\">\n";
  504. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n";
  505. $fp=fopen($basedir.$file,"r");
  506. $contents=fread($fp,filesize($basedir.$file));
  507. echo "<TEXTAREA NAME=\"code\" rows=\"$textrows\" cols=\"$textcols\">\n";
  508. echo htmlspecialchars($contents);
  509. echo "</TEXTAREA><BR>\n";
  510. echo "<center><INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Save\">\n";
  511. echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Cancel\"></center><BR>\n";
  512. echo "</FORM>";
  513. }
  514. echo $html_ender;
  515. break;
  516. //显示文件
  517. case "show":
  518.  
  519. //以文本格式显示文件
  520. $filelocation = $wdir.$file;
  521. $lastaction = "$basedir$file";
  522. html_header();
  523. //如果是图片则显示
  524. if($image == "1")
  525. {
  526. echo "<center><img src=\"$file\"></center>";
  527. }
  528. //如果是文本,显示.
  529. else
  530. {
  531. show_source($basedir.$file);
  532. }
  533. echo $html_ender;
  534. break;
  535. //创建新目录
  536. case "mkdir":
  537.  
  538. //如果该目录已经存在.
  539. if(file_exists($basedir.$wdir.$mkdirfile))
  540. {
  541. $lastaction = "$basedir$wdir$mkdirfile allready exists.";
  542. html_header();
  543. }
  544. //否则则创建
  545. else
  546. {
  547. $lastaction = "Created the directory $wdir$mkdirfile";
  548. html_header();
  549. mkdir($basedir.$wdir.$mkdirfile,0750);
  550. }
  551. displaydir();
  552. echo $html_ender;
  553. break;
  554. //生成新文件
  555. case "createfile":
  556. $filelocation = $wdir.$file;
  557. //编辑完毕,返回.
  558. if($done == "1")
  559. {
  560. $lastaction = "Created $file";
  561. html_header();
  562. $fp=fopen($basedir.$filelocation,"w");
  563. fputs($fp,stripslashes($code));
  564. fclose($fp);
  565. displaydir();
  566. }
  567. else
  568. {
  569. //如果文件已经存在
  570. if(file_exists($basedir.$filelocation))
  571. {
  572. $lastaction = "$file already exists.";
  573. html_header();
  574. displaydir();
  575. }
  576. else
  577. {
  578. $lastaction = "Creating $file";
  579. html_header();
  580. echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n";
  581. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n";
  582. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"createfile\">\n";
  583. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n";
  584. echo "<INPUT TYPE=\"HIDDEN\" NAME=\"done\" VALUE=\"1\">\n";
  585. echo "<TEXTAREA NAME=\"code\" rows=\"$textrows\" cols=\"$textcols\">\n";
  586. //用户选用Web页面
  587. if(isset($html))
  588. {
  589. echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n\n";
  590. echo "<html>\n";
  591. echo "<head>\n\n";
  592. echo " <title>Untitled</title>\n";
  593. echo "</head>\n";
  594. echo "<body>\n\n\n\n";
  595. echo "</body>\n";
  596. echo "</html>";
  597. }
  598. echo "</TEXTAREA><BR>\n";
  599. echo "<center><INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Create\">\n";
  600. echo "<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Cancel\"></center><BR>\n";
  601. echo "</FORM>";
  602. }
  603. }
  604. echo $html_ender;
  605. break;
  606. }
  607. ?>
posted @ 2015-08-25 21:27  Yxh_blogs  阅读(783)  评论(0编辑  收藏  举报