Php file processing is a note I made when I was learning php. in order to have a good study habit and to provide a learning reference for programmers, I would like to share my learning notes, I hope to help myself and everyone. This learning material mainly comes from the PHP and PHP5 Chinese manuals and online materials carefully explained by the LAMP brothers. we strongly recommend that friends who are interested in learning PHP choose the PHP carefully edited by the LAMP brothers.
File judgment function
Is_dir ()
Is_executable () determines whether it is an executable file
Is_file ()
Is_link () determines whether the file name is a symbolic connection
Is_readable ()
Is_uploader_fiel () determines whether the file is uploaded through HTTP POST
Is_writable ()
File attributes
File_exists ()
Filesize ()
Is_readable ()
Is_writeable ()
Filectime ()
Filemtime ()
Get the file name basename ()
Directory dirname ()
File path information pathinfo ()
Create file touch ($ file)
Delete file unlink ($ file)
Rename ("current file path", "target file path ")
Copy a file ("file name", "path ")
Read/write files
File_get_contents ()
File_put_contents ()
Fopen ("URL", mode)
Various modes:
R: open file in read-only mode r +: read/write mode w: open in write-only mode. if the file does not exist, create a file. if the file already contains content, overwrite w +: read/write mode: open in write-only mode. if the file does not exist, create a file. if the file already contains content, append a +: read/write mode B: open the file in binary mode (image, video) t: open a file in text mode
Fread () // read the variable fread({{file},filesize({text.txt ") with a fixed length "))
Fgetc () // read one character from the file at a time;
Fgets () // read a line of characters from the file at a time;
Feof ($ file) // returns true if an error occurs when the file is read or the file ends.
Write files
Fwrite ()
Move pointer inside file
Ftell ($ file) // returns the current pointer position
Fseek ($ file, 100, constant) // move the file pointer
Rewind ()
Basename (file path [, file suffix]) obtains the file name. The second parameter is to obtain the basic file name pathinfo (file path). analyze the current path and return an Associated array, extension to reference realpath (file relative path) display file absolute path filesize ($ file) calculation file size fileatime ($ file) display last accessed time filectime ($ file) file creation time filemtime ($ file) The last file update fileperms () returns the file attributes and permissions fileowner () to get the file owner
Directory operation:
Opendir () readdir () closedir () rewinddir () // The pointer returns the first directory.