Function |
Description |
Instance |
filesize ($file) |
|
!--? php tutorial //get file size in bytes echo ' size is " . FileSize (& #39; myfile.html& #39;). "bytes"; ?> |
fileowner ($file) filegroup ($file) |
|
//get file owner and group Echo "UID:". Fileowner (' myfile.html '); echo "GID:". Filegroup (' myfile.html '); ? |
Fileatime ($file) Filemtime ($file) |
These functions return the time at which a file was last accessed and modified to find out whether a file was modified after a specific date. |
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) |
This function returns a file license, which is used to check whether the file is readable, writable, or executable. |
Get Permissions in octal format echo "File permissions:". sprintf ('%0 ', fileperms (' myfile.html ')); ?> |
FileType ($file) |
This function returns the "type" of the file-whether it is connected, a directory, an attribute or a block device, or a regular file. Use it to test the nature of a file before performing an operation. |
Get file type echo "File type:". FileType (' myfile.html '); ?> |
Stat ($file) |
This is a "all-encompassing" function that returns the detailed statistics of a file, including its owner and its owning group, size, last modified time, and number of index nodes. If you need to get comprehensive file statistics in a separate function call, use this function instead of the ones listed earlier. |
Get file statistics Print_r (stat (' myfile.html ')); ?> |
Realpath ($file) |
This function converts a relative file path to an absolute file path and uses this function when it is necessary to find the exact location of a file on disk. |
Get absolute path Returns "/tmp/myfile.html" echo "File path:". Realpath ("./cook/book/http://www.cnblogs.com/myfile.html"); ?> |
BaseName ($file) DirName ($file) |
Given a full file path, these functions can be decomposed into individual components and return filenames and directories, respectively. |
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) |
This function reads the contents of a file into an array. Each element in the array represents a single row of files. This function is used to read the contents of a file into a variable so that it can be further processed. |
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"; } ?> |