PHP遍曆指定檔案夾下的所有檔案

來源:互聯網
上載者:User

PHP遍曆指定檔案夾下的所有檔案,如下代碼:

 
  1. <?php  
  2. session_start(); 
  3. if($Submit=="提交"){ 
  4.  $shili=$file_dir; 
  5. ?> 
  6. <html> 
  7. <head> 
  8. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
  9. <title>遍曆指定目錄下的所有檔案 - www.cxybl.com</title> 
  10. </head> 
  11.  
  12. <body> 
  13. <table width="350" height="150" border="0" cellpadding="0" cellspacing="0" background="images/324.jpg"> 
  14.   <form name="form1" method="post" action="index.php"> 
  15.   <tr> 
  16.     <td width="132" height="55"> </td> 
  17.     <td width="135"> </td> 
  18.     <td width="83"> </td> 
  19.   </tr> 
  20.   <tr> 
  21.     <td height="40"> </td> 
  22.     <td align="center"> 
  23.      <input name="file_dir" type="text" id="file_dir" size="18" maxlength="50"></td> 
  24.     <td> <input type="submit" name="Submit" value="提交"></td> 
  25.   </tr> 
  26.   <tr> 
  27.     <td height="55"> </td> 
  28.     <td> </td> 
  29.     <td> </td> 
  30.   </tr> 
  31.   </form> 
  32. </table> 
  33. <?php 
  34.        $shili = $file_dir ; 
  35.        if ( !file_exists ( $shili )){ 
  36.           print $shili."目錄不存在!" ; 
  37.       }else{   
  38.        $i = 0; 
  39.          if ( is_dir ( $shili )){                   //檢測是否是合法目錄 
  40.            if ($shi = opendir ( $shili )){          //開啟目錄 
  41.               while ($li = readdir( $shi )){       //讀取目錄 
  42.                   $i++ ; 
  43.             echo " $i: $li <br> " ;      } } }     //輸出目錄中的內容 
  44.          closedir ( $shi ) ;  }  ?> 
  45. </body> 
  46. </html> 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.