PHP Learning note--8. Files and directories

Source: Internet
Author: User
Tags file handling

1. File Handling functions

File_get_contents ()//Get the contents of a File/network resource

Faster functions with internal encapsulation of open/close operations

But because in fact, the contents of the file read all, for large files with caution

File_put_contents (' file ', content)//write content to file

If the file does not exist, it is created automatically

fopen (' file ', ' mode ')//Open a file, return a resource

R Read-only

r+ read-write, pointer overwrite write from file header

W Write, will clear first

A append mode, pointer in the last

Fread (resource, length)//Read the contents of a resource

Fwrite (resources, content)//write content to

Fclose (resources)//Close Resources

Fgets (Resource)//read a line of content, read the pointer down one line

Feof ()//Determine if the pointer is in the last row

File (Resource)//reads the contents of the files and splits them into arrays by rows, returning the data

Use caution for large files

Filemtime ()//File modification time

FileSize ()//Read File size

Unlink ()//delete files

2. Import the CSV file

When you need to enter the contents of the XLS file into the database, you can save it as a CSV file first

Fgetcsv () takes a row from the file pointer

The relevant specifications for the CSV file have been encapsulated, even though the CSV file has some

Special cases (such as blank lines, commas between fields, etc.), can also operate normally

3. Directory Operations

Opendir ()//Open Readdir ()//Read closedir ()//Off

Is_dir ()//whether directory mkdir ()//Create RMDIR ()//delete (only non-empty)

mkdir (' directory ', 0777,true); Turn on recursive creation

@zhnoah
Source: http://www.cnblogs.com/zhnoah/
This article is owned by me and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original
The right to pursue legal liability.

PHP Learning note--8. Files and directories

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.