不斷閱讀,你就會發現一些新內容!
表a
函數 |
說明 |
執行個體 |
filesize ($file) |
此函數以位元組為單位返回一個檔案的大小。它用於計算一個檔案在磁碟上佔有多少空間。 |
// get file owner and group echo "uid: " . fileowner('myfile.html'); echo "gid: " . filegroup('myfile.html'); ?> |
fileatime ($file) filemtime ($file) |
這些函數分別返回某一檔案最後被訪問及修改的時間,用於找出一個檔案在一個特定的日期後是否被修改。 |
// get file access/modification times echo "last accessed on: " . date("d-m-y", fileatime('myfile.html')); echo "last modified on: " . date("d-m-y", filemtime('myfile.html')); ?> |
fileperms ($file) |
此函數返回一個檔案許可,用它來檢查檔案是否可讀,可寫或可執行。 |
// get permissions in octal format echo "file permissions: " . sprintf('%0', fileperms('myfile.html')); ?> |
filetype ($file) |
此函數返迴文件的“類型”—是否串連,目錄,特性或塊裝置,或常規檔案。在執行某項操作前,用它來檢驗檔案的本質。 |
// get file type echo "file type: " . filetype('myfile.html'); ?> |
stat($file) |
這是一個“包羅永珍”的函數,它返回一個檔案的詳細統計資料,包括它的所有者與所屬組,大小,最後修改時間,索引節點數目。如果你需要在一個單獨的函數調用中獲得全面的檔案統計資料,請使用此函數而不是前面列舉的那些函數。 |
// get file statistics print_r(stat('myfile.html')); ?> |
realpath ($file) |
此函數將一個相對檔案路徑轉換為絕對檔案路徑,當需要找出一個檔案在磁碟上的準確位置,則使用此函數。 |
// get absolute path // returns "/tmp/myfile.html" echo "file path: " . realpath("./cook/book/http://www.cnblogs.com/myfile.html"); ?> |
basename ($file) dirname ($file) |
只要給定一個完整的檔案路徑,這些函數就能將其分解為各個組成部分,並分別返迴文件名和目錄。 |
// split directory and file names // returns "/usr/local/bin" echo "directory: " . dirname("/usr/local/bin/php"); // returns "php" echo "file: " . basename("/usr/local/bin/php"); ?> |
file($file) |
此函數將一檔案的內容讀入一數組。數組中的每一個元素代表一行檔案。此函數用於將檔案內容讀入一個變數中,以便對它進行進一步的加工。 |
// read file contents $lines = file('myfile.html'); // print line by line for($x=1; $x<=sizeof($lines); $x++) { ?echo "line $x: " . $lines[$x-1] . "n"; } ?> |
http://www.bkjia.com/PHPjc/445360.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445360.htmlTechArticle不斷閱讀,你就會發現一些新內容! 表a 函數 說明 執行個體 filesize ($file) 此函數以位元組為單位返回一個檔案的大小。它用於計算一個檔案在磁...