PHP gets directory creation time

In any case, find the time found in the directory in php? I tried filectime but only works with files.

+8
source share
9 answers

It should work for directories, here is what I get:

 $ php -r "echo filectime(__DIR__);" 1311596297 
+6
source

On unix, a folder is also a file. So this should work too.

 $folder = 'includes'; echo date ("F d YH:i:s.", filemtime($folder)); 

Exit

 October 06 2010 20:20:58. 
+4
source

You can use PHP stat function :

Collects statistics for a file named filename. If filename is a symbolic link, statistics come from the file itself, and not from the symbolic link.

Example:

 <?php $stat = stat('/your/path'); echo $stat['ctime']; ?> 

It returns the creation time as a Unix timestamp.

+3
source
+1
source

if (dose does not work) try clearstatcache (); before your filectime function;

0
source
 $filename='dirname'; date ("F d YH:i:s.", filectime($filename)) 

he will work.

0
source

Try this:

 $filename = 'media/'; echo "$filename was created modified: ".date("F d YH:i:s.", filectime($filename)); 
0
source

I tested both the filectime () and filemtime () functions on a Linux server, and they work correctly in directories, in the sense that they return a timestamp.

Then I tried to get the last modified date of the directory, renaming it via FTP, and then checking it again, and here's the weird thing that happened:

  • creation date timestamp was updated with current time
  • the last modified date was not updated at all

I think this could be due to the manipulation of FTP files instead of direct processing through the command line or system GUI.

On Windows, both the creation date and the date of the last change do not change when renaming a directory.

For your tests, I also suggest you take a look at the clearstatcache () function (which I also used in my test) to clear the PHP cache of file system information.

0
source

No, not reliable.

This is because ctime not about creation, but about change, as stated in Gordon's comment. Thus, although filectime() works with directories (at least on a Unix machine), it most likely will not give you the date you are looking for. See the notes on the PHP Doc page for filectime() :

Also note that in some Unix texts the ctime of a file is called the file creation time. This is not true. Most Unix file systems do not have time to create Unix files.

In other words, creating a new file in the directory is likely to change the ctime time in the directory. If you really need to keep track of the time of creation, you need to do the housework yourself.

0
source

Source: https://habr.com/ru/post/893493/


All Articles