PHP file Programming (i)-two ways to get file information

Source: Internet
Author: User
    1. Open File

    2. $file _path= "Text.txt";
    3. if ($fp =fopen ($file _path, "R")) {
    4. Information for removing files
    5. $file _info=fstat ($FP);
    6. echo "
      ";
    7. Print_r ($file _info);
    8. echo "
    9. ";

    10. Single Take-out

    11. $file _size= $file _info[' size ';
    12. The file size is calculated in bytes
    13. echo "File Size:". $file _size;
    14. echo "
      Time the file was last accessed: ". Date (" Y-m-d h:i:s ", $file _info[' atime ']); Atime "The time the file was last accessed"
    15. echo "
      Time the file was last modified: ". Date (" Y-m-d h:i:s ", $file _info[' mtime ']); Mtime "time when the file last content was modified"
    16. echo "
      File last change time: ". Date (" Y-m-d h:i:s ", $file _info[' CTime ']); CTime indicates "time when the file was last file owner/filegroup Modified"

    17. }else{

    18. echo "Failed to open file";
    19. }

    20. Close the file, this is very important

    21. Fclose ($FP);
    22. ?>

Copy Code

Mode 2, get file information

    1. The second way to get file information by bbs.it-home.org

    2. $file _path= "Text.txt";
    3. if (!file_exists ($file _path)) {
    4. echo "file does not exist";
    5. Exit ();
    6. }

    7. echo "
      ". Date (" Y-m-d h:i:s ", Fileatime ($file _path));

    8. echo "
      ". Date (" Y-m-d h:i:s ", Filemtime ($file _path));
    9. echo "
      ". Date (" Y-m-d h:i:s ", Filectime ($file _path));

    10. echo "
      ". Filemtime ($file _path);

    11. echo "
      ". Filectime ($file _path);
    12. ?>

Copy Code
  • 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.