当前位置:首页 > PHP教程 > php应用 > 列表

PHP实现的简单网络硬盘

发布:smiling 来源: PHP粉丝网  添加日期:2021-06-14 15:33:34 浏览: 评论:0 

这篇文章主要介绍了PHP实现的简单网络硬盘,涉及php动态创建文件夹及文件上传的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下,本文实例讲述了PHP实现的简单网络硬盘,分享给大家供大家参考,具体如下:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <html xmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  6. <title>disk online</title> 
  7. <style type="text/css"> 
  8. .font { 
  9.   font-family: Consolas; 
  10.   color: #369; 
  11.   font-size: 12px; 
  12. } 
  13. .box { 
  14.   font-family: Consolas; 
  15.   font-size: 13px; 
  16.   color: #369; 
  17.   border: 1px solid #000; 
  18. } 
  19. .btn { 
  20.   font-family: "微软雅黑"; 
  21.   font-size: 12px; 
  22.   color: #FFF; 
  23.   background-color: #369; 
  24.   border: 1px solid #666; 
  25.   width: 80px; 
  26. } 
  27. </style> 
  28. </head> 
  29. <body class="font"> 
  30. <div align="right"><a href="upload.php" class="box">操作完 一下刷新</a></div> 
  31. <?php 
  32. /* 
  33.  * code written by mot 
  34.  * 2012 - 5 - 20 
  35.  *在根目录下面新建一个 名字为 x 的文件夹 存放上传文件 
  36.  */ 
  37. if(isset($_REQUEST['del'])){ 
  38.   unlink($_REQUEST['del']); 
  39. } 
  40. set_time_limit(0); 
  41. if(isset($_POST['button'])) 
  42. if(isset($_FILES['file'])){ 
  43.   move_uploaded_file($_FILES['file']['tmp_name'], ".\\x\\".$_FILES['file']['name']); 
  44. } 
  45. ?> 
  46. <table width="100%" border="0"> 
  47.   <tr> 
  48.     <td class="box"> 
  49.     <div> 
  50.     <form action="upload.php" method="post" enctype="multipart/form-data"> 
  51.     <p>File <input class="box" name="file" type="file" /></p> 
  52.     <p align="center"><input class="btn" name="button" type="submit" 
  53.       value="上传" /></p> 
  54.     </form> 
  55.     </div> 
  56.     </td> 
  57.   </tr> 
  58. </table> 
  59. <table width="100%" border="0"> 
  60.   <tr> 
  61.     <th width="40%" class="box">文件名</th> 
  62.     <th width="20%" class="box">类型</th> 
  63.     <th width="10%" class="box">MD5</th> 
  64.     <th width="20%" class="box">大小</th> 
  65.     <th width="20%" class="box">操作</th> 
  66.   </tr> 
  67.   <?php 
  68.   $hl = opendir(".\\x\\"); 
  69.   while(false != $info = readdir($hl)){ 
  70.     if($info == '.' || $info == '..') continue; 
  71.     $x[] = $info; 
  72.   } 
  73.   if(isset($x)) 
  74.   foreach ($x as $file) { 
  75.   $type = explode('.', $file); 
  76.   $name = $type[0]; 
  77.   $type = $type[1]; 
  78.   $size = sprintf("%.2f",abs(filesize(".\\x\\".$file))/1024/1024); 
  79.   ?> 
  80.   <tr> 
  81.     <td class="box"><a href="\file\x\<?=$file?>"><?=$name ?></a></td> 
  82.     <td class="box"><?=$type ?></td> 
  83.     <td class="box"><?=md5_file(".\\x\\".$file)?></td> 
  84.     <td class="box"><?=$size." MB" ?></td> 
  85.     <td class="box"><a href="upload.php?del=<?=".\\x\\".$file?>">remove</a></td> 
  86.   </tr> 
  87.   <?php 
  88.   } 
  89.   ?> 
  90. </table> 
  91. </body> 
  92. </html> 

希望本文所述对大家的php程序设计有所帮助。

Tags: PHP网络硬盘

分享到: