PHP file, folder (directory) Operation function Summary
This article to give you a summary of some of the commonly used folder/file directory operation function Summary in PHP, these are simply introduced some basic methods to make a note.
1. Create directory (mkdir)
BOOL MkDir (string $pathname [, int $mode [, bool $recursive [, Resource $context]])
2. Determine if the file exists (file_exist)
BOOL File_exists (String $filename)
3, check whether the specified file is a directory, generally also used to determine whether the directory exists (IS_DIR)
BOOL Is_dir (String $filename)
Note: The result of this function will be cached. Please use Clearstatcache () to clear the cache.
4. Determine if the given file name is a normal file (is_file)
BOOL Is_file (String $filename)
5. Lock or Release files (flock)
BOOL Flock (String $filename, String $lock [, Mix $block])
The lock parameter can be one of the following values:
To get a shared lock (read program), set lock to Lock_sh (previous version of PHP 4.0.1 to 1).
To obtain an exclusive lock (written program), set the lock to LOCK_EX (the previous version of PHP 4.0.1 to 2).
To release the lock (regardless of share or exclusive), set lock to Lock_un (the previous version of PHP 4.0.1 to 3).
If you do not want flock () to block when locked, add LOCK_NB to lock (the previous version of PHP 4.0.1 is set to 4).
Block is optional. If set to 1 or true, the other process is blocked when the lock is made.
Tip: You can release the lock operation through Fclose (), which is also called automatically when the code is executed. For example:
6. Determine if the given file name is a symbolic connection (Is_link)
BOOL Is_link (String $filename)
Note: The result of this function will be cached. Please use Clearstatcache () to clear the cache.
7. Delete directory (RmDir) This function only removes empty directories (rmdir)
BOOL RmDir (String $dirname)
8. Delete Files (unlink)
BOOL Unlink (string $filename)
9. Get permissions for a file or directory (fileperms)
Mix fileperms (filename)
Return permissions as octal values
Hint: The result of this function will be cached. Please use Clearstatcache () to clear the cache.
10. Get the type of the specified file or directory (filetype)
Mix filetype (filename)
If successful, 7 possible values are returned (FIFO char dir block link file unknown). If it fails, it returns false. For example:
Hint: The result of this function will be cached. Please use Clearstatcache () to clear the cache.
11. Read the directory file (opendir readir closedir)
Resource Opendir (String $path [, Resource $context])
Opens a directory handle that can be used later in the Closedir (), Readdir (), and Rewinddir () calls.
String Readdir (Resource $dir _handle)
Returns the file name of the next file in the directory. The file name is returned as a sort in the file system.
void Closedir (Resource $dir _handle)
Closes the directory stream specified by Dir_handle. The stream must be opened previously by Opendir ().
void Rewinddir (Resource $dir _handle)
Resets the directory stream specified by Dir_handle to the beginning of the directory.
The following is an example of a complete read directory file:
12. Renaming files or directories (rename)
BOOL Rename (oldname, newname, context)
Description: The same is true for directories. The system returns the result of the operation, which returns TRUE if successful, and FALSE if it fails.
If you want to move a file or directory, simply set the renamed path to the new path, for example:
13, copy ( copy) file (copy)
BOOL Copy (source, destination)
Note: This operation cannot be performed on the directory, and if the target file (above/b/1.gif) already exists, the original file will be overwritten, and if you want to move the file, use the rename () function.
14 . Get the available space for the directory (disk_free_space)
Disk_free_space (directory)
15. Determine if the specified file is writable (is_writable or is_writeable)
BOOL Is_writable (file)
Note: If the file exists and is writable, the return true;file parameter can be a directory name that allows for a writable check, and the result of this function is cached. Please use Clearstatcache () to clear the cache. For example:
16. Create a temporary file with a unique file name (tmpfile) in read-write (w+) mode
Resource Tmpfile ()
17. Change the file permission mode (chmod)
bool chmod (file [, mode])
mode is optional. Specify the new permissions. This parameter consists of 4 numbers:
The first number is always 0.
The second number specifies the owner's permissions
The second number specifies the permissions of the user group to which the owner is a member
The fourth number stipulates the rights of all other persons
Possible values (if you want to set multiple permissions, make a total of the following numbers):
1-Execute Permissions
2-Write permissions
4-Read Permissions
18. Extension function, method
PHP reads directories and tables displays the functions of files in the directory
PHP Delete all files in directory and directory
For more files, folder (directory) functions please refer to:
PHP Filesystem functions
Articles you may be interested in
- PHP Empty (delete) the file under the specified directory, do not delete the Directory folder method
- PHP determines whether a file or directory (folder) exists
- Linux chmod (file or folder permission settings) command parameters and usage details
- MySQL Import and export by command. An instance of a SQL file backup data operation
- PHP Extract the birthday date from the ID number and the function to verify whether it is a minor
- PHP writes or appends data to a file
- Linux Delete files, Folder command RM command detailed
- Linux command file directory Management Cat command
http://www.bkjia.com/PHPjc/992746.html www.bkjia.com true http://www.bkjia.com/PHPjc/992746.html techarticle php file, folder (directory) Operation function Summary This article to give you a summary of some of the common folder/file directory operation function Summary in PHP, these are simply introduced a ...