Common php file operation function reference table. Keep reading and you will find some new content! Table a function indicates the instance filesize ($ file). This function returns the size of a file in bytes. It is used to calculate a file that is constantly read in the magnetic field, and you will find some new content!
Table
Function |
Description |
Instance |
Filesize ($ File) |
This function returns the size of a file in bytes. It is used to calculate how much space a file occupies on the disk. |
// Get file owner and group Echo "uid:". fileowner('myfile.html '); Echo "gid:". filegroup('myfile.html '); ?> |
Fileatime ($ File) Filemtime ($ File) |
These functions return the last access time and modification time of a file to identify whether a file has been 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 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-connection, directory, feature, block device, or regular file. Before performing an operation, use it to check the nature of the file. |
// Get file type Echo "file type:". filetype('myfile.html '); ?> |
Stat ($ file) |
This is an all-encompassing function that returns detailed statistics of a file, including its owner and group, size, last modification time, and number of index nodes. If you need to obtain comprehensive file statistics in a separate function call, use this function instead of the previously listed functions. |
// Get file statistics Print_r(stat('myfile.html ')); ?> |
Realpath ($ File) |
This function converts a relative file path to an absolute file path. This function is used when you need to find the exact location of a file on the 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 complete file path, these functions can divide it into components and return the file names 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 content of a file into an array. Each element in the array represents a row of files. This function is used to read the file content into a variable for further processing. |
// 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 "; } ?> |
Success! Table a function indicates the instance filesize ($ file). This function returns the size of a file in bytes. It is used to calculate a file in the magnetic...