PHP file System processing method Summary,
This paper summarizes and analyzes the processing methods of PHP file system. Share to everyone for your reference, as follows:
File type
With Linux as a model, only file, dir or unknow three types can be obtained in Windows
Under Linux/unix, block, Char, dir, FIFO, file, link, unknown7 types
Blocks: Block settings file, disk partition, floppy drive, CD-ROM, etc.
Char: Character device, I/O (in input and output) devices in characters, such as keyboards, printers, etc.
dir: Directory is also a file/directory file
FIFO: Information pipeline, transfer from one program to another process
file: Common Files type such as text file, executable file
Link: Linked file, equivalent to a shortcut under Windows
Unknown : Unknown type
1. File Property Handling functions
FileType ("directory or file name") Gets the type
Is_dir--Determine if a given file name is a directory
Is_file--Determine if the given file name is a normal file
Is_link--Determine if the given file name is a symbolic connection
Is_executable (); --Determine if the given file name is executable
File_exists ();--whether the file exists
FileSize ();--Return file size
Is_readable ();--whether the file is readable
Is_writeable ();--whether the file is writable
Filectime ();--File creation time
Filemtime ();--File modification time
Fileactime ();--Last file access time
Stat ();--File status, returns an array of information about a given file
BOOL Ftruncate (resource handle, int size);
Accepts the file pointer handle as a parameter and intercepts the file size to size. Returns TRUE if successful, and FALSE if it fails.
BOOL Rename (string oldname, string newname [, resource context]);
2. Catalogue
Directory Properties
* BaseName (url[, extension]); Returns the file name * dirname (URL); Directory name * pathinfo (URL); Path information
Example:
$path = "/var/www/html/page.php"; Echo basename ($path);//returns Page.phpecho basename ($path, ". php"); Pageecho dirname ($PAHT);///var/www/html$arr=pathinfo ($PAHT); $arr ["dirname"]///var/www/html$arr["basename"]// page.php$arr["extension"]//. php
Traverse Directory
Opendir (URL), Readdir (URL);//Returns the current directory pointer to only one file name, and moves the directory pointer back one closedir (URL), Rewinddir (URL);//Reset the directory pointer to the beginning
Statistics Directory Size
The size of the statistics directory can only be created by recursive functions to add up the directory files;
Statistics disk size can be used Disk_free_space (URL), and disk_total_space (URL);
Creating and deleting Directories
mkdir (URL);//Create directory rmdir (URL);//Delete empty directory unlink (URL);//delete file
Deleting a non-empty directory can only build its own recursive function;
Copy Directory
Copy ($scrfile, $to);//Copy file
The ability to customize the recursive function for directory replication
3. Basic operation of the file
fopen (URL); fclose (URL);
Write file
int fwrite (resoure handle,strint string[,int length]);
Returns the number of characters written or false
Fputs () is an alias of Fwrite ()
int file_put_contents (string filename, string data [, int flags [, resource context]]);
and sequentially call fopen (), fwrite (), and the fclose () function.
Read file
String Fread (resource handle, int length);
Reads up to length bytes from a file pointer handle. When the function reads the length of a byte or reaches EOF
String file_get_contents (string filename [, bool Use_include_path [, resource context [, int offset [, int maxlen]]]); Array file (string filename [, int use_include_path [, resource context]]);
Each cell in the array is the corresponding line in the file, including the newline character.
String fgets (resource handle [, int length]), String fgetc (resource handle); int ReadFile (string filename [, bool US E_include_path [, Resource context]]);
Reads a file and writes to the output buffer.
If you access a remote file, you must activate the "allow_url_fopen" option in your PHP configuration file to open the remote file using the fopen () function
When you use the FTP protocol to connect remote files, you can only open files in "read Only" or "write only" mode.
Move file pointer
int Ftell (resource handle);
Returns the position of the file pointer specified by handle, which is the offset in the file stream.
int fseek (resource handle, int offset [, int whence]);
Sets the location of the file pointer in the file associated with the handle. The new location, measured in bytes from the beginning of the file header, is the position specified by whence plus offset. The whence de value is defined as:
Seek_set -the set position equals the offset byte.
Seek_cur -Sets the position to the current position plus offset.
seek_end -Set the position to the end of the file plus offset. (to move to the position before the end of the file, you need to pass a negative value to offset.) )
BOOL Rewind (resource handle);
Set the handle file location pointer to the beginning of the file stream
More about PHP related content readers can view the topic: "PHP File Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document tips summary (including word, excel,access,ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1133092.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133092.html techarticle PHP File System processing Method Summary, this paper summarizes and analyzes the PHP file system processing method. Share to everyone for reference, as follows: File type with Linux as model, in win ...