Php file operations-notes for common file operations

Source: Internet
Author: User
There are many File operation functions in php. I will introduce you to the usage of common file operation functions in php. 1. get the file name: basename (); 2. get the directory where the file is located: dirname (); 3. pathi... there are many File operation functions in php. I will introduce you to the usage of common file operation functions in php.

1. get the file name: basename ();

2. obtain the directory where the file is located: dirname ();

3. obtain the file information through pathinfo (). The Returned result is an array, including the path, full name, file name, and extension.

The instance code is as follows:

$file = '/com/netingcn/error.log'; print_r(pathinfo($file));

Result:

Array( [dirname] => /com/netingcn [basename] => error.log [extension] => log [filename] => error )

4. determine whether the file exists: is_file ();

5. check whether the directory exists: is_dir ();

6. determine whether a file or directory exists: file_exists ();

7. read all the file content: file () or file_get_contents (). file () returns an array with a row of elements. file_get_contents () returns all the file content as a String;

8. write the file fwrite, for example:

The instance code is as follows:

 

Article address:

Reprint at will ^ please include the address of this article!

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.