Jump to content

Archived

This topic is now archived and is closed to further replies.

vidar

Checking age of file

Recommended Posts

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.


Share this post


Link to post
Share on other sites
This function might help:

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

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.