PHP file Processing--operation files

Source: Internet
Author: User

In addition to reading and writing the contents of the file, the file itself can also be manipulated, such as copying files, renaming, viewing the modified date and so on. PHP built-in a large number of file manipulation functions, commonly used file functions are the following table:

Function prototypes Function description Example
bool Copy (String path1,string path2) copy (' tm.txt ', ' ... /tm.txt ')
bool Rename (String filename1,string filename2) Rename the name1 to name2 rename (' 1.txt ', ' test.txt ')
bool unlink (string filename) Delete file, Success returns TRUE, Failure returns false. unlink (' tm.txt ')
int fileatime (string filename) Returns the last time the file was accessed, returning the fileatime (' test.txt ')
int filemtime (string filename) Returns the last time the file was modified, returning the date (" y-m-d h:i:s ", Filemtime (" Test.txt "))
int filesize (string filename) Gets the size of the file filename (bytes) FileSize (' 1.txt ')
Array PathInfo (string name[,int options]) Returns an array that contains the path information for the name of the file. There are dirname,basename and extension. You can set the information to be returned by option, with Pathinfo_dirname, Pathinfo_basename, and Pathinfo_extension. The default is to return all $arr =pathinfo ('/tm/s1/16/4/9/1.txt '); foreach ($arr as $method = = $value) { echo $method. ":" $value. " <br> ";
}
string realpath (string filename) Returns the absolute path of the file filename, such as D:\wampserver\www\test\test.txt realpath (test.txt)
Array stat (string filename) Returns an array that includes information about the file, such as the file size mentioned above, the last modification time, and so on. $arr =stat (' test.txt '); foreach ($arr as $method = = $value) {echo $method. ":" $value. " <br> ";}

Description

When reading and writing files, except for a few functions such as file (), ReadFile (), other operations must first open the file with the fopen () function, and finally close the file with the fclose () function, and the information function of the file (FileSize (), filemtime (), etc.) You do not need to open the file, as long as the file exists.

PHP file Processing--operation files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.