<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>

            PHP文件與目錄操作的方法

            時間:2025-10-02 23:56:08 php語言

            PHP文件與目錄操作的方法

              主要介紹了PHP文件與目錄操作,涉及php針對文件與目錄的遍歷、判斷與排序相關操作技巧,注釋中備有較為詳細的說明,需要的朋友可以參考下。

              本文實例講述了PHP文件與目錄操作。分享給大家供大家參考,具體如下:

              文件目錄相關函數

              <?php

              /pic/p>

              function outputcurfiles ($allowedtypes, $thedir){

              /pic/p>

              if (is_dir ($thedir)){

              /pic/p>

              $scanarray = scandir ($thedir);

              /pic/p>

              /pic/p>

              /pic/p>

              for ($i = 0; $i < count ($scanarray); $i++){

              if ($scanarray[$i] != "." && $scanarray[$i] != ".."){

              /pic/p>

              if (is_file ($thedir . "/" . $scanarray[$i])){

              /pic/p>

              /pic/p>

              if (is_writable ($thedir. "/" . $scanarray[$i]) &&  is_readable($thedir . "/" . $scanarray[$i])){

              /pic/p>

              $thepath = pathinfo ($thedir . "/" . $scanarray[$i]);

              if (in_array ($thepath['extension'], $allowedtypes)){

              /pic/p>

              echo $scanarray[$i] . "<br />";

              }

              }

              }

              }

              }

              } else {

              echo "對不起,這個目錄不存在.";

              }

              }

              $allowedtypes = array ("txt","html");

              outputcurfiles ($allowedtypes, "testfolder");

              /pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/

              function recurdir ($thedir) {

              /pic/p>

              try {

              if ($adir = opendir ($thedir)){

              /pic/p>

              while (false !== ($anitem = readdir ($adir))){

              /pic/p>

              if ($anitem != "." && $anitem != ".."){

              /pic/p>

              /pic/p>

              if (is_dir ($thedir . "/" . $anitem)){

              ?><span style="font-weight: bold;" mce_style="font-weight: bold;"><?php echo $anitem; ?></span><?php

              ?><P style="margin-left: 10px;" mce_style="margin-left:10px;"><?php

              recurdir ($thedir . "/" . $anitem );

              ?></P><?php

              } elseif (is_file ($thedir . "/" . $anitem)){

              /pic/p>

              echo $anitem . "<br />";

              }

              }

              }

              } else {

              throw new exception ("Sorry, directory could not be openend.");

              }

              } catch (exception $e) {

              echo $e->getmessage();

              }

              }

              echo "<br />/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/<br /><br />";

              recurdir("testfolder");

              /pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/p>

              echo "<br />/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/pic/<br /><br />";

              function sortfilesbydate ($thedir){

              /pic/p>

              if (is_dir ($thedir)){

              /pic/p>

              $scanarray = scandir ($thedir);

              $finalarray = array();

              /pic/p>

              /pic/p>

              /pic/p>

              for ($i = 0; $i < count ($scanarray); $i++){

              if ($scanarray[$i] != "." && $scanarray[$i] != ".."){

              /pic/p>

              if (is_file ($thedir . "/" . $scanarray[$i])){

              /pic/p>

              $finalarray[$thedir . "/" . $scanarray[$i]] = filemtime ($thedir . "/" . $scanarray[$i]);

              }

              }

              }

              /pic/p>

              asort ($finalarray);

              return ($finalarray);

              } else {

              echo "對不起,這個目錄不存在.";

              }

              }

              /pic/p>

              $sortedarray = sortfilesbydate ("testfolder");

              /pic/p>

              while ($element = each ($sortedarray)){

              echo "File: " . $element['key'] . " was last modified: " . date ("F j, Y h:i:s", $element['value']) . "<br />";

              }

              ?>

            【PHP文件與目錄操作的方法】相關文章:

            php中目錄文件操作詳談02-21

            PHP遍歷目錄文件常用方法03-06

            php操作excel文件的方法小結12-02

            PHP開發:linux 父目錄權限影響子目錄文件操作02-13

            PHP文件怎么操作01-29

            php查找指定目錄下指定大小文件的方法09-11

            PHP常用的文件操作函數10-24

            php文件操作函數解釋02-09

            用PHP遍歷目錄下的全部文件03-17

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看