简体   繁体   中英

how I can get The last time the file is opened in php

How can I get the last time the file was opened in PHP?

Can anyone help me?

I just found the stat() function but this just returns time of last modification but I need last time the file was opened.

You can use the function fileatime() .

The following example:

<?php
    $filename = "/Users/rafaelalmeida/projects/UFP-API/README.md";

    if (file_exists($filename)) {
        echo "$filename was last accessed: " . date("F d Y H:i:s.", fileatime($filename));
    }

The result from the code above is: /Users/rafaelalmeida/projects/UFP-API/README.md was last accessed: February 17 2017 00:29:20. .

You can read more about fileatime() function here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM