find the creation date of a file in php

You can use the filectime() function in PHP to get the creation time of a file. This function takes a file path as a parameter and returns the Unix timestamp of when the file was last changed (including the creation time).

Here's an example:

main.php
$file = 'path/to/your/file.txt';
if (file_exists($file)) {
    $creationTime = filectime($file);
    echo "File creation time: " . date("F d Y H:i:s.", $creationTime);
} else {
    echo "File not found.";
}
207 chars
8 lines

This code checks if the file exists and if it does, it retrieves the creation time using filectime() and formats it using the date() function.

Note that the creation time of a file is not always available on every operating system or file system, so filectime() may return the last modification time instead.

gistlibby LogSnag