PHP擷取資料夾清單,檔案清單

來源:互聯網
上載者:User
PHP擷取資料夾清單,檔案清單
  1. /**
  2. * Goofy 2011-11-30
  3. * getDir()去資料夾清單,getFile()去對應檔案夾下面的檔案清單,二者的區別在於判斷有沒有“.”尾碼的檔案,其他都一樣
  4. */
  5. //擷取檔案目錄列表,該方法返回數組
  6. function getDir($dir) {
  7. $dirArray[]=NULL;
  8. if (false != ($handle = opendir ( $dir ))) {
  9. $i=0;
  10. while ( false !== ($file = readdir ( $handle )) ) {
  11. //去掉"“.”、“..”以及帶“.xxx”尾碼的檔案
  12. if ($file != "." && $file != ".."&&!strpos($file,".")) {
  13. $dirArray[$i]=$file;
  14. $i++;
  15. }
  16. }
  17. //關閉控制代碼
  18. closedir ( $handle );
  19. }
  20. return $dirArray;
  21. }
  22. //擷取檔案清單
  23. function getFile($dir) {
  24. $fileArray[]=NULL;
  25. if (false != ($handle = opendir ( $dir ))) {
  26. $i=0;
  27. while ( false !== ($file = readdir ( $handle )) ) {
  28. //去掉"“.”、“..”以及帶“.xxx”尾碼的檔案
  29. if ($file != "." && $file != ".."&&strpos($file,".")) {
  30. $fileArray[$i]="./imageroot/current/".$file;
  31. if($i==100){
  32. break;
  33. }
  34. $i++;
  35. }
  36. }
  37. //關閉控制代碼
  38. closedir ( $handle );
  39. }
  40. return $fileArray;
  41. }
  42. //調用方法getDir("./dir")……
  43. ?>
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.