Directory operation in php (8)

Directory operation Windows and linux file model
division _ _ _ _ _ _ _ _ 1byte 1024b=1KB 1024KB=1MB 1024MB=1GB 1024GB=1TB file_exists() Judge whether a file or directory exists filetype() Obtain the file type is_dir() Judge whether it is a directory is_file() Judge whether it is a file is_readable() Whether it is readable is_writeable( )Writable filectime() Creation time fileatime() Access time filemtime( ) Modification time All return timestamps The path of the directory






























windows: C:\xampp\htdocs
Linux: /usr/local/apache2/htdocs/demo.php
Note
1. The delimiter of the directory under windows is \, and the delimiter of the linux directory is /. But windows also recognizes / as a directory separator, so when we write, we write /
2. Try to use /, because \ represents the escape character in php
Directory operation
mkdir() Create directory
First parameter
path
Second parameter
permission There should be no quotation marks when setting (it is not useful under windows)
. The meaning of each part is represented by the
owner
group, the
others , the
number meaning
r: readable 4
w: writable 2
x: executable 1
The third parameter
is whether to allow recursion Create a directory, the default value is false
rmdir() Delete empty directory
unlink() Delete file 
dirname() Return directory name
basename() Return file name
pathinfo() Return an array containing directory name, file name, suffix name, base file name
Traversal Directory
1. Open directory resource
opendir()
Note: The opendir Chinese directory cannot be opened, you need to use iconv. Convert utf-8 to gbk, because the php file is in utf-8 format, but the windows system is in GBK format, so it cannot read
2. Read from the resource
readdir()
returns the file name of the next file in the directory. When reading to the end, it will return false .
Note
1. In the Windows system, the first and second files readdir read the file names are always . and ..; . represents the current directory, .. represents the parent directory
2, When doing traversal, deletion, and copying, you must exclude . and ..
3. Exclusion method
1. readdir (resource)
        readdir (resource)
2. Make judgment $fileName != '.' && $fileName != '.. ' 3.
Close directory resources
closedir ( resources ) Windows and Linux file model
division _













filesize() Get the size of the file, return the result in bytes
8bit=1byte
1024b=1KB
1024KB=1MB
1024MB=1GB
1024GB=1TB
file_exists() Determine whether a file or directory exists
filetype() Obtain the file type
is_dir() Determine whether it is a directory
is_file() Determines whether it is a file
is_readable() Whether it is readable or not
is_writeable() Whether it is writable
filectime() Creation time
fileatime() Access time filemtime(
) Modification time All
returned are timestamps
Directory path
windows: C:\xampp\ htdocs
Linux: /usr/local/apache2/htdocs/demo.php
Note
1. The delimiter of the directory under windows is \, and the delimiter of the linux directory is /. But windows also recognizes / as a directory separator, so we write / when we write
2. Try to use /, because \ represents the escape character in php
Directory operation
mkdir() Create directory
First parameter
Path
Second parameter
When setting permissions, there should be no quotation marks (it is not useful under Windows)
. The meaning of each part is the meaning of the
owner
group, the
others , the
number meaning
r: readable 4
w: writable 2
x: executable 1
The third parameter
is allowed or not Create directories recursively, the default value is false
rmdir() delete empty directories
unlink() delete files 
dirname() return directory name
basename() return file name
pathinfo() return an array containing directory name, file name, suffix name, base file name
Traverse the directory
1. Open the directory resource
opendir()
Note: The opendir Chinese directory cannot be opened, you need to use iconv. Convert utf-8 to gbk, because the php file is in utf-8 format, but the windows system is in GBK format, so it cannot read
2. Read from the resource
readdir()
returns the file name of the next file in the directory. When reading to the end, it will return false .
Note
1. In the Windows system, the first and second files readdir read the file names are always . and ..; . represents the current directory, .. represents the parent directory
2, When doing traversal, deletion, and copying, you must exclude . and ..
3. Exclusion methods
1. readdir(resource)
        readdir(resource)
2. Make judgment $fileName != '.' && $fileName != '..'
3. Close directory resource
closedir (resource)

Guess you like

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