note 126358 added to function.filemtime

From: Date: Sun, 22 Aug 2021 12:33:14 +0000
Subject: note 126358 added to function.filemtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-216818@lists.php.net to get a copy of this message
filemtime(..) only works with files on your server. $T=filesize("index.php"); // Works. $T=filesize("/public_html/dir/index.php"); // Works. But the following will not work. $T=filesize("https://mydomain.com/dir/index.php"); // Will not work. Same domain but using web address. $T=filesize("https://otherdomain.com/dir/index.php"); // Other domain, will not work. To get file date for other sites try: (Note: Time zone may be in G.M.T. and not your local timezone) $T = getFileDate("https://mydomain.com/dir/index.php"); $T = getFileDate("https://otherdomain.com/dir/index.php"); function getFileDate($filePath){ // Same as filemtime(..) but also works with remote files. // EG. = print date("j/m/Y, g:i:sa (e)",getFileDate("https://abc.com/file.jpg")); // File not found then will return -307756800 ( 1/04/1960) $ret = -(3562 *24*60*60); // 1/04/1960 3562= seconds to 1/01/1970 $ch = curl_init($filePath); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Try and get the file modification date. curl_setopt($ch, CURLOPT_FILETIME, true); $result = curl_exec($ch); if($result===false){ die(curl_error($ch)); return $ret; } $ret = curl_getinfo($ch, CURLINFO_FILETIME); curl_close($ch); return $ret; } ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 2a02:c7d:3299:5300:7c3d:fe19:9ff:81ab) ---- Manual Page -- https://php.net/manual/en/function.filemtime.php Edit -- https://main.php.net/note/edit/126358 Del: integrated -- https://main.php.net/note/delete/126358/integrated Del: useless -- https://main.php.net/note/delete/126358/useless Del: bad code -- https://main.php.net/note/delete/126358/bad+code Del: spam -- https://main.php.net/note/delete/126358/spam Del: non-english -- https://main.php.net/note/delete/126358/non-english Del: in docs -- https://main.php.net/note/delete/126358/in+docs Del: other reasons-- https://main.php.net/note/delete/126358 Reject -- https://main.php.net/note/reject/126358 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216818) next »