This paper summarizes and analyzes the processing method of PHP file system. Share to everyone for your reference, specific as follows:
File type
With Linux as a model, only three types of file, dir, or unknow can be obtained in Windows
Under Linux/unix, block, Char, dir, FIFO, file, link, unknown7 type
Block: Blocks settings file, disk partition, floppy drive, CD-ROM, etc.
Char: Character device, I/O (in input output) a device in characters, such as a keyboard, printer, etc.
dir: Directory is also a file/directory file
FIFO: Information pipeline, transferring from one program to another process
file: Normal files type such as text file, executable file
Link: A linked file, equivalent to a shortcut under Windows
Unknown : Unknown type
1. File Property handler function
FileType ("directory or filename") get 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--Determines whether a given file name is a symbolic connection
Is_executable (); --Determine if a given file name is executable
File_exists ();-File exists
FileSize ();--Returns the file size
Is_readable ();--File is readable
Is_writeable ();-whether the file can be written
Filectime ();--File creation time
Filemtime ();--File modification time
Fileactime ()--File last 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 a size. Returns TRUE if successful, and returns FALSE if it fails.
BOOL Rename (string oldname, string newname [, resource context]);
2. Table of Contents
Directory Properties
* BaseName (url[, extension]); Returns the filename
* dirname (URL); Directory Name
* pathinfo (URL); Path information
Example:
$path = "/var/www/html/page.php";
Echo basename ($path);//return page.php
Echo basename ($path, ". php");//page
echo 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 a filename for the current directory pointer and moves the directory pointer backward by a
closedir (URL);
Rewinddir (URL)//reset directory pointer to start
Statistics Directory Size
The size of the statistic directory can only be established by recursive functions to add up the directory files;
Statistics disk size can be used disk_free_space (URL); and disk_total_space (URL);
Create and delete directories
mkdir (URL);//Create directory
rmdir (URL);//Delete empty directory
unlink (URL);//delete file
Deleting a non-empty directory can only establish its own recursive function;
Copy Directory
Copy ($scrfile, $to);//Copying files
Custom recursive function to implement directory replication function
3. Basic operation of files
fopen (URL);
fclose (URL);
Write to File
int fwrite (resoure handle,strint string[,int length]);
Returns the number of characters written or false
Fputs () is an alias for fwrite ()
int file_put_contents (string filename, string data [, int flags [, resource context]]);
and call fopen (), fwrite () and fclose () in turn.
Reading files
String Fread (resource handle, int length);
Reads up to length bytes from the file pointer handle. When the function reads the length of bytes, 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 line breaks.
String fgets (resource handle [, int length]);
String fgetc (resource handle);
int ReadFile (string filename [, bool Use_include_path [, Resource context]]);
Reads a file and writes it to the output buffer.
If you are accessing a remote file, you must activate the "allow_url_fopen" option in the PHP configuration file to open the remote file using the fopen () function
When you use the FTP protocol to connect to a remote file, you can only open the file 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 file pointer position in the file associated with the handle. The new location, measured in bytes, starting at the file header, plus offset at the location specified by whence. The whence de value is defined as:
Seek_set -set position equals offset byte.
seek_cur -set position plus offset for current position.
Seek_end -Sets the position for the end of the file plus offset. (You need to pass a negative value to offset before you move to the end of the file.) )
BOOL Rewind (resource handle);
Sets the handle file location pointer to the beginning of the file stream
More interested in PHP related content readers can view the site topics: "PHP file Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "Basic PHP Grammar Introduction Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with your PHP programming.