PHP中檔案類型 檔案屬性 路徑以及 檔案相關的函數

來源:互聯網
上載者:User

標籤:style   blog   color   使用   檔案   io   

一: 檔案類型判斷:

1.is_dir()  判斷是不是目錄

2.is_file() 判斷是不是檔案

3.is_executeable() 判斷是不是可執行檔

4.is_readable()  判斷是不是可讀檔案

5.is_writable() 判斷是不是可寫檔案

6.is_link()  判斷是不是捷徑

 

二:檔案屬性:

1.file_exits()  檔案是否存在

2.filesize() 檔案大小

3.filectime()  檔案建立時間

4.filemtime() 檔案修改的時間

5.fileaction() 檔案最後訪問的時間

6.stat()  檔案的狀態 返回的是一個數組

    [uid] => 0       //使用者號    [gid] => 0      //組號    [rdev] => 4    [size] => 0    [atime] => 1405691106  //最後訪問時間    [mtime] => 1405691106  //修改時間    [ctime] => 1405691106  //檔案建立時間
7.計算檔案大小:

  function GetFileSize($size){        $dw="Byte";        if($size >= pow(2,40)){            $size=round($size/pow(2,40),2);            $dw="TB";        }else if($size >= pow(2,30)){            $size=round($size/pow(2,30),2);            $dw="GB";        }else if($size >= pow(2,20)){            $size=round($size/pow(2,20),2);            $dw="MB";        }else if($size >=pow(2,10)){            $size=round($size/pow(2,10),2);            $dw="KB";        }else{            $dw="Bytes";        }        return $size.$dw;    }
8.檔案路徑:
1.windows : /
  2.Liunx ? \
3.DIRECTORY_SEPARATOR:目錄分隔字元,是定義php的內建變數
  4.不管是window 還是Liunx都支援“/” 在PHP和Apache設定檔中也使用/
9.檔案函數:
  1.basename(url):取檔案名稱
  2.dirname(url); 取檔案目錄名稱,如要想要取上一級 只需要嵌套就可以driname(driname(url));
  3.pathinfo(url);路徑資訊; 返回的是一個數組
  4.filename(ulr); 檔案名稱;
  5.extension(url); 副檔名;

聯繫我們

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