PHP--File operations (create, copy, move, delete)

Source: Internet
Author: User

Createfolder

BOOL mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = False [, Resour CE $context ]])

Parameters

pathname

The path to the directory.

mode

The default mode is 0777, which means the maximum possible access rights. For more information on mode, please read the chmod () page.

Note: mode is ignored under Windows.

You might want to specify the pattern in octal numbers, which means that the number should begin with 0. The pattern is also modified by the current umask and can be changed with Umask ().

recursive(递归)

Allows the creation of nested directories specified in the pathname .

Allows the path specified in the nested directory to be created.

context

Note: added support for context in PHP 5.0.0. For a description of the context, see Streams.

If the specified directory does not exist, it is created, returns True, and if the specified directory exists, the creation fails, returning false

file

BOOL Touch ( string $filename [, int $time = time () [, int $atime ]])

Parameters

filename

The file name to set.

time

The time to set. If no parameters are supplied time , the current system time is used.

atime

If this parameter is given, the access time for the given file is set to atime , otherwise it will be set time to. If these two parameters are not given, the current system time is used.

If the specified file does not exist, it is created, returns True, and if the specified file exists, the creation fails and returns false

files and folders are the same for creation. such as:

Create the folder "abc" with mkdir, and if the file already has "ABC" in the previous directory, the creation fails

Create the file "abc" with TOUCHR, and if the folder already has "ABC" in the previous directory, the creation fails

Copy

BOOL Copy ( string $source , string $dest [, resource $context ])

Copy files to Dest ( must be a file, not a path (folder))

Write if not present, overwrite write if file exists in target path

Movingmethod One, direct call to move the method rename

BOOL Rename ( string $oldname , string $newname [, resource $context ])

Move a file or folder

Files can be renamed across disk partitions

Equivalent to Shearing

The path ( folder ) already exists in the $newname path and is not moved;

For the path ( file ) already exists in the $newname path, the move is overwritten;

method Two, first copy, and then delete the original directory (file), but also to achieve the purpose of the move (fee time)

DeleteFolder

BOOL rmdir ( string $dirname [, resource $context ])

An attempt dirname was made to delete the specified directory . The directory must be empty and have the appropriate permissions . A E_WARNING level of error will occur on failure

Parameters

dirname

The path to the directory.

context

Note: added support for context in PHP 5.0.0. For a description of the context, see Streams.

File

BOOL unlink ( string $filename [, resource $context ])

Deleted filename . Similar to the unlink () function of Unix C. A level of error is generated E_WARNING when an error occurs.

Parameters

filename

The path to the file.

context

Note: added support for context in PHP 5.0.0. For a description of the context, see Streams.

PHP--File operations (create, copy, move, delete)

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.