PHP common file Operation function Reference Table _php Tutorial

Source: Internet
Author: User
Tags filegroup
Keep reading and you'll find something new!

Table A






!--? php tutorial
//get file size in bytes
echo ' size is " . FileSize (& #39; myfile.html& #39;). "bytes";





//get file owner and group
Echo "UID:". Fileowner (' myfile.html ');
echo "GID:". Filegroup (' myfile.html ');





These functions return the time at which a file was last accessed and modified to find out whether a file was 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 '));



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

Get Permissions in octal format
echo "File permissions:". sprintf ('%0 ', fileperms (' myfile.html '));



This function returns the "type" of the file-whether it is connected, a directory, an attribute or a block device, or a regular file. Use it to test the nature of a file before performing an operation.

Get file type
echo "File type:". FileType (' myfile.html ');

Stat ($file)

This is a "all-encompassing" function that returns the detailed statistics of a file, including its owner and its owning group, size, last modified time, and number of index nodes. If you need to get comprehensive file statistics in a separate function call, use this function instead of the ones listed earlier.

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



This function converts a relative file path to an absolute file path and uses this function when it is necessary to find the exact location of a file on disk.

Get absolute path
Returns "/tmp/myfile.html"
echo "File path:". Realpath ("./cook/book/");





Given a full file path, these functions can be decomposed into individual components and return filenames 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 contents of a file into an array. Each element in the array represents a single row of files. This function is used to read the contents of a file into a variable so that it can be further processed.

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";
?> true techarticle keep reading and you'll find something new! Table A function Description instance filesize ($file) This function returns the size of a file in bytes. It is used to calculate a file in the magnetic ...

  • Related 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: 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.