filectime vs filemtime for file modification time?
filemtime: Represents when the data or content is changed or modified, not including that of meta data such as ownership or ownergroup.
filectime: Represents the time when the meta data or inode data of a file is altered, such as the change of permissions, ownership or group.
so filemtime
is the solution.
As you're dealing with image caching, filectime
is inappropriate - it marks the last time:
when the permissions, owner, group, or other metadata from the inode is updated
You want to know if the image file content has changed - if it's been resized, cropped or replaced entirely.
Therefore, filemtime
is more suitable for your application:
when the data blocks of a file were being written to, that is, the time when the content of the file was changed
If you don't want the ?
to always appear, set filemtime
to a variable first and test for it:
$filemtime = @filemtime("/images/123.png");
<img src="/images/123.png<?= $filemtime ? '?' . $filemtime : ''?>" />
Better still, test for the existence of the file with file_exists()
before using filemtime
.
Note: In most Unix filesystems, a file is considered changed when its inode data is changed; that is, when the permissions, owner, group, or other metadata from the inode is updated. See also filemtime() (which is what you want to use when you want to create "Last Modified" footers on web pages) and fileatime().
From the manual
So you want to use filemtime
.