PHP File related Operations

Source: Internet
Author: User

Because of the next contact with the use of PHP crawler, and crawled data sometimes in order to save database resources, need to save as a local text file, so here to organize a PHP related file operation functions. First, open the file

First Open File fopen

Resource fopen (String $filename, String $mode)
FileName: File path to be opened

Mode: Modes to open files


Writes are rewritten if you want to append a to the end of the file.


Second, read the file

Read one row fgets () in the file

Fgets (Resource $handle, [, int $length])
Handle is an open file handle with a default length of 1KB, which is 1024 bytes. Stops when a line break, EOF, or a specified length is reached.
Read character FGETSC
Fgetc (Resource $handle)
The handle file pointer must be valid and must point to a file that was successfully opened by fopen () or Fsockopen (), which returns a string containing a character that is obtained from the file that handle points to, and returns false when it encounters EOF.
Third, obtain the file attributeLast access Time Fileatime ()
int Fileatime (string $filename)
Gets the last access time, returns false on failure, returns the Unix timestamp (the time () function in format 1970-01-01t00:00:00z,php) file modified Filemtime ()
int Filemtime (string $filename)
Returns the time the file was last modified when successful, false when it fails, and time can return file size in Unix timestamp filesize ()
int FileSize (string $filename)
Returns the number of bytes in the file size on success, returns false on failure, and generates a e_waring-level error file type filetype ()
String filetype (string $filename)
Possible return values are Fifo,char,dir,block,link,file,unknown file synthesis Information stat ()
Array stat (string $filename)
Returns information about the last access, modification time, and size of the file.



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.