PHP filemtime() Function
In this chapter you will learn:
- Definition for PHP filemtime() Function
- Syntax for PHP filemtime() Function
- Parameter for PHP filemtime() Function
- Return for PHP filemtime() Function
- Note for PHP filemtime() Function
- Example - Get last time the file content was modified
Definition
PHP function filemtime() returns last modified time.
Syntax
PHP filemtime() Function has the following syntax.
filemtime(filename)
Parameter
Parameter | Is Required | Description |
---|---|---|
filename | Required. | File to check |
Return
It returns a Unix timestamp for the time, which you then need to convert using a call to date().
This function returns the last change time as a Unix timestamp on success, FALSE on failure.
Note
The result of this function are cached. Use clearstatcache() to clear the cache.
Example
The filemtime() function returns the last time the file content was modified.
<?PHP//from j a v a 2 s . c om
$contacts = "test.txt";
$atime = fileatime($contacts);
$mtime = filemtime($contacts);
$atime_str = date("F jS Y H:i:s", $atime);
$mtime_str = date("F jS Y H:i:s", $mtime);
print "File last accessed: $atime_str\n";
print "File last modified: $mtime_str\n";
echo filemtime("test.txt");
echo "\n";
echo "Last modified: ".date("F d Y H:i:s.",filemtime("test.txt"));
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP fileowner() Function
- Syntax for PHP fileowner() Function
- Parameter for PHP fileowner() Function
- Return for PHP fileowner() Function
- Note for PHP filemtime() Function
- Example - Get the file owner
Home » PHP Tutorial » PHP File Functions