Forum Moderators: coopster
<?php
$dh = opendir(temp) or die ("Could not open temp directory");
while (false!== ($file = readdir($dh)))
{
if ($file!= "." && $file!= "..")
{
unlink("temp/$file") ;
echo "<font face=Verdana size=1>All Files Deleted...</font>";
}
}
?>
but i wanted to do some simple validation on it so that it only executes the deletion once a day.
basically, the script is going to execute everytime but i dont want the contents of the entire folder to be deleted everytime the script is executed. i want the script to run 2 validation rules
firstly to check if the server time is between 11:30PM and 11:49PM if it is not then the script doesnt do anything, but if it is the script basically checks a log file to see if the script has already been executed by someone else, if it has then it doesnt do nothing. but if it hasnt, it deletes the entire contents of the "temp" folder and then writes a log so that when someone else tries to execute the script it wont delete.
I've created a peace of perl code that executes a script only once a day by logging data in a file. the code looks like this:
open(TIME, "runonce.log");
$lastrun = <TIME>;
close(TIME);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if($lastrun == $yday) {
print "Content-type: text/html\n\n";
exit;
} else {
open(TIME, ">runonce.log");
print TIME $yday;
close(TIME);
}
Maybe that can help someone to help me get this done in PHP. any help would be very much appreciated.
cheers
linda