Saturday, March 7, 2020
Using the PHP Function to Find When a File Was Modified
Using the PHP Function to Find When a File Was Modified If your website contains time-sensitive information- or even if it doesnt- you may want to display the last time a file was modified on the website. This gives users an accurate idea of how up to date the information on a page is. You can automatically draw this information from the file itself using the ââ¬â¹filemtime() PHP function. The filemtime() PHP function retrieves the Unix timestamp from the file. The date function converts the Unix timestamp time. This timestamp indicates when the file was last changed. Example Code to Display File Modification Dateà When you use this code,à replace myfile.txt with the actual name of the file you are dating.ââ¬â¹ ?php // outputs myfile.txt was last modified: December 29 2002 22:16:23. $filename myfile.txt; if (file_exists($filename)) {à à echo $filename was last modified: . date (F d Y H:i:s., filemtime($filename)); } ? Other Uses for Filemtime() Function In addition to time-stamping web articles, the filemtime() function can be used to select all articles older than a specified time for the purpose of deleting all old articles. It can also be used to sort articles by age for other purposes. The function can come in handy when dealing with browser caching. You can force the download of a revised version of a stylesheet or page using the filemtime()à function. Filemtime can be used to capture the modification time of an image or other file on a remote site. Information on Filemtime() Function The resultsà of the filemtime() function are cached. Theà clearstatcache() function clears the cache.If the filemtime () function fails, the code returns false.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.