PHP: how can I get file creation date?

To get the file creation date in PHP, you can use the filectime() function. This function returns the creation time of the file, as a Unix timestamp.

Here's an example of how to use filectime():

<?php

$filename = '/path/to/file.txt';

if (file_exists($filename)) {
    $file_creation_date = filectime($filename);
    echo "File was created on: " . date('Y-m-d H:i:s', $file_creation_date);
} else {
    echo "File does not exist.";
}

This code will output the creation date of the file in the format "Y-m-d H:i:s", e.g. "2022-01-01 12:00:00".

Watch a course Learn object oriented PHP

Note: The filectime() function will return the creation time of the file on the filesystem, not the creation time of the file's contents. If the file has been moved or copied from another location, the creation time may not accurately reflect the actual creation time of the file's contents.