Backend Development 3 min read

Understanding PHP filectime() Function: Syntax, Usage, and Examples

This article explains the PHP filectime() function, its syntax, how it returns a file's creation timestamp, how to format the timestamp with date(), includes practical code examples, and notes the difference from filemtime() and fileatime().

php中文网 Courses
php中文网 Courses
php中文网 Courses
Understanding PHP filectime() Function: Syntax, Usage, and Examples

The filectime() function in PHP retrieves the creation time of a specified file.

Syntax of filectime()

<code>filectime(string $filename): int|false</code>

Here $filename is the path to the file. The function returns an integer timestamp representing the file's creation time, or false on error.

The returned timestamp counts seconds since the Unix epoch (1970‑01‑01 00:00:00 UTC). It can be formatted into a readable date using the date() function.

Example of filectime()

How to use filectime() to obtain a file's creation time:

<code>$filename = 'path/to/file.txt';
$ctime = filectime($filename);
if ($ctime === false) {
    echo "Unable to get file creation time";
} else {
    echo "File creation time: " . date('Y-m-d H:i:s', $ctime);
}
</code>

The script first sets the file path, calls filectime() , stores the result in $ctime , checks for false , and if successful formats the timestamp with date() .

Notes

filectime() returns the creation time, not the last modification or access time. For those, use filemtime() and fileatime() respectively.

Summary

The filectime() function obtains a file's creation timestamp, which can be converted to a readable date with date() ; it returns false if the creation time cannot be retrieved.

backendfile handlingdate functionfilectimefile timestamp
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.