ultrus Posted December 28, 2010 Share Posted December 28, 2010 Hello, I'm using curl to grab a new solar image once an hour or so from the Solar Dynamics Observatory (example below). I'm trying to archive new images and am struggling with that. If I download an image, the filetime() function returns the current time since I downloaded it and wrote it to a fresh file. The result is that the file is always "new", even if the image hasn't changed on the SDO website. Do you have an idea on how to check the last modified time of a file through curl or other means so that I'm not downloading duplicate images? Thanks a ton! //fetch image $ch = curl_init("http://www.somewebsite.com/theimage.jpg"); curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); $file = "../images/latest/theimage.jpg"; $fp = fopen($file, "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); //this part is no good... //get last modified date if (file_exists($file)) { $filetime = filemtime($file); } Quote Link to comment https://forums.phpfreaks.com/topic/222791-checking-if-file-on-another-website-has-changed-have-starter-curl-example/ Share on other sites More sharing options...
trq Posted December 28, 2010 Share Posted December 28, 2010 Do you have an idea on how to check the last modified time of a file through curl The file system on the server is responsible for such information. Its not normally made available to requesting clients. Quote Link to comment https://forums.phpfreaks.com/topic/222791-checking-if-file-on-another-website-has-changed-have-starter-curl-example/#findComment-1152027 Share on other sites More sharing options...
ultrus Posted December 28, 2010 Author Share Posted December 28, 2010 I'm digging, so far I might be able to get the Last-Modified header of a remote file using curl: http://stackoverflow.com/questions/845220/get-the-last-modified-date-of-a-remote-file Not working yet as I'm using it within a class. I'll post if I get it working. Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/222791-checking-if-file-on-another-website-has-changed-have-starter-curl-example/#findComment-1152031 Share on other sites More sharing options...
trq Posted December 28, 2010 Share Posted December 28, 2010 That will be all that is available. Not real reliable but It's likely your best option. Quote Link to comment https://forums.phpfreaks.com/topic/222791-checking-if-file-on-another-website-has-changed-have-starter-curl-example/#findComment-1152033 Share on other sites More sharing options...
ultrus Posted December 28, 2010 Author Share Posted December 28, 2010 SOLVED Source: http://stackoverflow.com/questions/845220/get-the-last-modified-date-of-a-remote-file $curl = curl_init("http://www.somewebsite.com/theimage.jpg"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_NOBODY, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FILETIME, true); $result = curl_exec($curl); if ($result === false) { die (curl_error($curl)); } $timestamp = curl_getinfo($curl, CURLINFO_FILETIME); if ($timestamp != -1) { //otherwise unknown echo date("Y-m-d H:i:s", $timestamp); //etc } Quote Link to comment https://forums.phpfreaks.com/topic/222791-checking-if-file-on-another-website-has-changed-have-starter-curl-example/#findComment-1152038 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.