How does php Get file attributes? Introduction to PHP's methods for obtaining file attributes (with code)

Source: Internet
Author: User
Tags echo date
PHP gets file attributes can be implemented in a variety of functions, each of which allows us to get a variety of information about the file, and then we will look at the different ways to get the file properties of PHP.

PHP Gets the file attributes last modified time:

< php  $file = ' test.txt ';  echo Date (' R ', Filemtime ($file));  ? >

Returns a timestamp that says Unix, which is commonly used in caching techniques.

The relevant PHP gets the file attributes of the last accessed time Fileatime (), Filectime () when the permissions of the file, owner, all groups or other inode metadata is updated time, Fileowner () function returns the file owner

$owner = Posix_getpwuid (Fileowner ($file));

(Non-Window System), Ileperms () Gets the file permissions,

< php  $file = ' dirlist.php ';  $perms = substr (sprintf ('%o ', Fileperms ($file)),-4);  echo $perms;  ? >

FileSize () returns the number of bytes in the file size:

< PHP  //output similar to: somefile.txt:1024 bytes  $filename = ' somefile.txt ';  Echo $filename. ': ' . FileSize ($filename). ' bytes ';  ? >

PHP gets all the information about the properties of a file with a function stat () function that returns an array:

< php  $file = ' dirlist.php ';  $perms = stat ($file);  Var_dump ($perms);  ? >
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: 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.