A Brief Introduction to how to obtain file attributes in PHP

Source: Internet
Author: User

PHP: Get file attributes latest modification time:

 
 
  1. < ?php  
  2. $file = 'test.txt';  
  3. echo date('r', 
    filemtime($file));  
  4. ?> 

The unix timestamp is returned, which is commonly used in cache technology.

Related PHP file properties are also obtained by fileatime (), filectime () when the object's permissions, owner, metadata in all groups or other inode is updated, the fileowner () function returns the file owner.

$ Owner = posix_getpwuid (fileowner ($ file ));

(Non-window system), ileperms () Get file permissions,

 
 
  1. < ?php  
  2. $file = 'dirlist.php';  
  3. $perms = substr(sprintf
    ('%o', fileperms($file))
    , -4);  
  4. echo $perms;  
  5. ?> 
  6.  

Filesize () returns the number of bytes of the file size:

 
 
  1. <? Php
  2. // The output is similar to: somefile.txt:
    1024 bytes
  3. $ Filename = 'somefile.txt ';
  4. Echo $ filename .':'
    . Filesize ($ filename). 'bytes ';
  5. ?>
  6.  

PHP obtains all information about the file attributes. There is a function stat () that returns an array:

 
 
  1. < ?php  
  2. $file = 'dirlist.php';  
  3. $perms = stat($file);  
  4. var_dump($perms);  
  5. ?> 
  6.  


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.