Jump to content


Photo

Checking age of file


  • Please log in to reply
6 replies to this topic

#1 vidar

vidar
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationNorway

Posted 30 May 2006 - 07:18 AM

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.




-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
| [!--sizeo:1--][span style="font-size:8pt;line-height:100%"][!--/sizeo--]I'm to be found at [a href="http://www.vidark.com" target="_blank"]www.vidark.com[/a][!--sizec--][/span][!--/sizec--] |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Vidar

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 01:59 PM

This function might help:

filemtime -- Gets file modification time
[a href=\"http://www.php.net/filemtime\" target=\"_blank\"]http://www.php.net/filemtime[/a]
~ D Kuang

#3 vidar

vidar
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationNorway

Posted 30 May 2006 - 02:31 PM

[!--quoteo(post=378372:date=May 30 2006, 03:59 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 30 2006, 03:59 PM) View Post[/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


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
| [!--sizeo:1--][span style="font-size:8pt;line-height:100%"][!--/sizeo--]I'm to be found at [a href="http://www.vidark.com" target="_blank"]www.vidark.com[/a][!--sizec--][/span][!--/sizec--] |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Vidar

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 03:28 PM

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...
~ D Kuang

#5 vidar

vidar
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationNorway

Posted 30 May 2006 - 07:00 PM

[!--quoteo(post=378400:date=May 30 2006, 05:28 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 30 2006, 05:28 PM) View Post[/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... 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--]

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

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
| [!--sizeo:1--][span style="font-size:8pt;line-height:100%"][!--/sizeo--]I'm to be found at [a href="http://www.vidark.com" target="_blank"]www.vidark.com[/a][!--sizec--][/span][!--/sizec--] |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Vidar

#6 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 31 May 2006 - 12:22 PM

<?php
$mod = filemtime("test.txt");
$now = mktime();
$dif = $now - $mod;
echo ($dif < 3600) ? "Less than an hour ($dif seconds)" : "Over an hour ($dif seconds)";
?>


#7 vidar

vidar
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationNorway

Posted 31 May 2006 - 05:50 PM


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.



-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
| [!--sizeo:1--][span style="font-size:8pt;line-height:100%"][!--/sizeo--]I'm to be found at [a href="http://www.vidark.com" target="_blank"]www.vidark.com[/a][!--sizec--][/span][!--/sizec--] |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Vidar




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users