You should learn PHP in this pose (4)

1、fopen() fwrite() fclose() fiel_put_contents

1) fopen(path,'xx') opens a file xx=r is opened in read-only mode and the pointer points to the head xx=r+ read-write mode opens xx=w write mode, and clears the file content, the pointer executes Head, if it does not exist, create xx=w+ read and write mode, the same as above xx=a write mode and execute the pointer to the head, but the write will overwrite the previous content, if it does not exist, create xx=a+ read and write mode, Other same as above 2) fwrite(

handle,content) writes text to the file
3) flcose($path) closes the file
4) file_put_contents('file',content) writes content to the file

Application scenarios: do file caching and do website logging, etc.

2、fread() feof() fgets() fgetss() fgetc() file_get_contents() file()

1)fread(handle,

size) Get the uppercase content of the specified byte from a file
2) feof($handle) determines whether the pointer has reached the end
3) fgets() reads a line from the file
4) fgetss() reads a line and comes to html
4) fgetc() reads a character
from a file 5) file_get_contents() gets contents from a file handle
6) file() same as above

Application scenario: When the concurrency is not very high, the file lock mechanism can be configured as a queue function

for example:

handle=fopen(′1.txt′,′r′);while(!feof(

handle)){

echo fgetc($handle);

}
fclose($handle);

3、file_exists()

1) file_exists() checks whether a file or directory exists

In the application scenario, when we upload pictures, we determine whether the directory exists, and if it does not exist, create it.

for example:

handle=′uploads/test′;if(!fileexists(

handle)){

mkdir($handle,0777,true);

}

4、is_dir() is_file() is_link() is_readable() is_writeable() is_writable() is_uploaded_file() is_executable()

1) Is is_dir() a directory
2) Is_file() a file

Application scenario: When we loop through a directory, we can determine whether it is a directory, and if it is, we will traverse it recursively

5、copy() move_uploaded_file() rename()

1)copy(one,

two)
2)move_uploaded_file()

Application scenario: upload pictures, move temporary files to the specified directory

3)rename()

6、filesize() filetype()

1) filesize() gets the size of the file
2) filetype() gets the type of the file

7 、 pathinfo ()

1) pathinfo() returns information about the path

8、dirname() basename()

1) dirname() returns the directory part of the path
2) basename() returns the file part of the path

9 、 fileatime () filemtime () filectime () touch ()

1) fileatime() gets the last access time of the
file 2
) filemtime() gets the modification time of the file 3) filectime() gets the modification time of the file
4) touch() sets the access and modification time of the file

10、mkdir() unlink() rmdir()

1) mkdir(path, 0777, true) creates a file 2) unlink(

file) delete file
3) rmdir() delete directory

11、feof() fseek() rewind() ftell()

1) feof() tests whether the file has reached the end of the file
2) fsweek() locates the pointer in the file
3) rewind() rewinds the position of the file pointer
4) ftell() returns the position where the file is read and written

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324818807&siteId=291194637