vidar Posted May 30, 2006 Share Posted May 30, 2006 I have made me a script to generate a picture from many different pictures, also with text on.This script does make two different pictures, but that's not importaint.What i had in mind was to check that age of the generated file before it run the script that i have now.By using the filemtime, i get the last modification time... i managed that. But it is in an exact time.How would i have to make the codes to do this:- mod-time - 1 hour.In other words i want to do this:- if mod-time is older then 1 hour, continiue with script, or else, do to ../gallery/photos.....If i get this to work i'll splitt it later, because this two different pictures had different rate of refreshing.Thanks for the time to read this. Quote Link to comment https://forums.phpfreaks.com/topic/10759-checking-age-of-file/ Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 This function might help:filemtime -- Gets file modification time[a href=\"http://www.php.net/filemtime\" target=\"_blank\"]http://www.php.net/filemtime[/a] Quote Link to comment https://forums.phpfreaks.com/topic/10759-checking-age-of-file/#findComment-40237 Share on other sites More sharing options...
vidar Posted May 30, 2006 Author Share Posted May 30, 2006 [!--quoteo(post=378372:date=May 30 2006, 03:59 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 30 2006, 03:59 PM) [snapback]378372[/snapback][/div][div class=\'quotemain\'][!--quotec--]This function might help:filemtime -- Gets file modification time[a href=\"http://www.php.net/filemtime\" target=\"_blank\"]http://www.php.net/filemtime[/a][/quote]Yeah, i have been there and made it to work, but how to do the rest... then i got a problem.I probably could set a time using this timesystem, but f.ex take - 1 hour... how would that be?And also in case i get it to work.Will i place the if with all the rest of my code in one of the cases?Thanks for the reply Quote Link to comment https://forums.phpfreaks.com/topic/10759-checking-age-of-file/#findComment-40249 Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 Erm... To set the modification/creation time you can use touch()[a href=\"http://www.php.net/touch\" target=\"_blank\"]http://www.php.net/touch[/a]They use UNIX timestamps, so if you want to take an hour just use ($date - 3600) or whatever. I don't know what "if" you are talking about... Quote Link to comment https://forums.phpfreaks.com/topic/10759-checking-age-of-file/#findComment-40265 Share on other sites More sharing options...
vidar Posted May 30, 2006 Author Share Posted May 30, 2006 [!--quoteo(post=378400:date=May 30 2006, 05:28 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 30 2006, 05:28 PM) [snapback]378400[/snapback][/div][div class=\'quotemain\'][!--quotec--]I don't know what "if" you are talking about...[/quote]I'll try again...the situateion is like this....I got a script, it generate 2 pictures. But it takes maybe 1.5 sec to run. To make the script be faaster i was thinking that if the files that is generated is newer then 1 hour, then don't run the generatting part.So i win 1.5 sec to pass that part.So my "if" would be like... [i]if, file.jpg is older then 1 hour, run script, if not, [!--coloro:#009900--][span style=\"color:#009900\"][!--/coloro--]header("Location: ../gallery/index.php?twg_noborder=true")[!--colorc--][/span][!--/colorc--][/i]Hope this clear out a little (i know the "if" i made here have nothing to do with programing, it's just to explain) The Green text is the final part of my script and shold be like that... (bouth cases should end with that)thanks again for the time Quote Link to comment https://forums.phpfreaks.com/topic/10759-checking-age-of-file/#findComment-40338 Share on other sites More sharing options...
zq29 Posted May 31, 2006 Share Posted May 31, 2006 [code]<?php$mod = filemtime("test.txt");$now = mktime();$dif = $now - $mod;echo ($dif < 3600) ? "Less than an hour ($dif seconds)" : "Over an hour ($dif seconds)";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10759-checking-age-of-file/#findComment-40538 Share on other sites More sharing options...
vidar Posted May 31, 2006 Author Share Posted May 31, 2006 Thanks... it helped alot.I also got one script like this:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$age = filemtime("../gallery/pictures/Photos/Weather/1overlay2.jpg") + 3600;if (time() < $age) { print ("Fresh"); } else{ print("Old"); }[/quote]This one is the one i'll be using... pretty much like this i guess. Quote Link to comment https://forums.phpfreaks.com/topic/10759-checking-age-of-file/#findComment-40637 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.