In addition to reading and writing the contents of the file, the file itself can also be manipulated, such as copying files, renaming, viewing the modified date and so on. PHP built-in a large number of file manipulation functions, commonly used file functions are the following table:
| Function prototypes |
Function description |
Example |
| bool Copy (String path1,string path2) |
|
copy (' tm.txt ', ' ... /tm.txt ') |
| bool Rename (String filename1,string filename2) |
Rename the name1 to name2 |
rename (' 1.txt ', ' test.txt ') |
| bool unlink (string filename) |
Delete file, Success returns TRUE, Failure returns false. |
unlink (' tm.txt ') |
| int fileatime (string filename) |
Returns the last time the file was accessed, returning the |
fileatime (' test.txt ') |
| int filemtime (string filename) |
Returns the last time the file was modified, returning the |
date (" y-m-d h:i:s ", Filemtime (" Test.txt "))
|
| int filesize (string filename) |
Gets the size of the file filename (bytes) |
FileSize (' 1.txt ') |
| Array PathInfo (string name[,int options]) |
Returns an array that contains the path information for the name of the file. There are dirname,basename and extension. You can set the information to be returned by option, with Pathinfo_dirname, Pathinfo_basename, and Pathinfo_extension. The default is to return all |
$arr =pathinfo ('/tm/s1/16/4/9/1.txt '); foreach ($arr as $method = = $value) { echo $method. ":" $value. " <br> ";
} |
| string realpath (string filename) |
Returns the absolute path of the file filename, such as D:\wampserver\www\test\test.txt |
realpath (test.txt) |
| Array stat (string filename) |
Returns an array that includes information about the file, such as the file size mentioned above, the last modification time, and so on. |
$arr =stat (' test.txt '); foreach ($arr as $method = = $value) {echo $method. ":" $value. " <br> ";} |
Description
When reading and writing files, except for a few functions such as file (), ReadFile (), other operations must first open the file with the fopen () function, and finally close the file with the fclose () function, and the information function of the file (FileSize (), filemtime (), etc.) You do not need to open the file, as long as the file exists.
PHP file Processing--operation files