Common File operation functions of php refer to Table _ PHP Tutorial

Source: Internet
Author: User
Common php file operation function reference table. Keep reading and you will find some new content! Table a function indicates the instance filesize ($ file). This function returns the size of a file in bytes. It is used to calculate a file that is constantly read in the magnetic field, and you will find some new content!

Table

Function

Description

Instance

Filesize

($ File)

This function returns the size of a file in bytes. It is used to calculate how much space a file occupies on the disk.

// Get file owner and group
Echo "uid:". fileowner('myfile.html ');
Echo "gid:". filegroup('myfile.html ');
?>

Fileatime

($ File)

Filemtime

($ File)

These functions return the last access time and modification time of a file to identify whether a file has been modified after a specific date.

// Get file access/modification times
Echo "last accessed on:". date ("d-m-y", fileatime('myfile.html '));

Echo "last modified on:". date ("d-m-y", filemtime('myfile.html '));
?>

Fileperms

($ File)

This function returns a file license used to check whether the file is readable, writable, or executable.

// Get permissions in octal format
Echo "file permissions:". sprintf ('% 0', fileperms('myfile.html '));
?>

Filetype

($ File)

This function returns the "type" of the file-connection, directory, feature, block device, or regular file. Before performing an operation, use it to check the nature of the file.

// Get file type
Echo "file type:". filetype('myfile.html ');
?>

Stat ($ file)

This is an all-encompassing function that returns detailed statistics of a file, including its owner and group, size, last modification time, and number of index nodes. If you need to obtain comprehensive file statistics in a separate function call, use this function instead of the previously listed functions.

// Get file statistics
Print_r(stat('myfile.html '));
?>

Realpath

($ File)

This function converts a relative file path to an absolute file path. This function is used when you need to find the exact location of a file on the disk.

// Get absolute path
// Returns "/tmp/myfile.html"
Echo "file path:". realpath ("./cook/book/http://www.cnblogs.com/myfile.html ");
?>

Basename

($ File)

Dirname

($ File)

Given a complete file path, these functions can divide it into components and return the file names and directories respectively.

// Split directory and file names
// Returns "/usr/local/bin"
Echo "directory:". dirname ("/usr/local/bin/php ");

// Returns "php"
Echo "file:". basename ("/usr/local/bin/php ");
?>

File ($ file)

This function reads the content of a file into an array. Each element in the array represents a row of files. This function is used to read the file content into a variable for further processing.

// Read file contents
$ Lines = file('myfile.html ');

// Print line by line
For ($ x = 1; $ x <= sizeof ($ lines); $ x ++ ){
? Echo "line $ x:". $ lines [$ X-1]. "n ";
}
?>


Success! Table a function indicates the instance filesize ($ file). This function returns the size of a file in bytes. It is used to calculate a file in the magnetic...

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.