Daily file deletion, and recreation. Error in the logic.
Posted: Sun Oct 01, 2006 2:23 am
This code is meant to check to see if ip.txt is more than a day old, if so I want it deleted then recreated. This is for a unique counter I'll be employing on my webbie once I get this done. I'm not sure why, it says error dividing by zero,since the file doesn't exist, yet I thought I instructed it to create the file with this bit:
however, like I said, it brings back an error.
Code: Select all
(!file_exists()) {Code: Select all
<?php
#path to the file which I want to use
$path = "iplog/";
#code to create my file in the case that it was deleted or never created
$create_it = fopen($path . 'ip.txt', 'a');
#make sure path is indeed a directory.
if(is_dir($path)) {
#handle to open that path
$handle = opendir($path);
#read the dir if so
while ($file = readdir($handle)) {
#find that file now!!!
if (is_file($path.$file)) {
#time comparison, to eventually check if this file has exists 1 day!
$diff = round((time() - filectime($path.$file))/3600/24);
#if it has exists KILL THE BASTARD!!!!!
if ($diff < 1) {
#AHHH file died : (
unset($file);
#make sure he died, shoot him twice in the head, Godfather 1 style, make sure they're dead
if(!file_exists($file)){
#ahh, thank God for resurrection, my file lives again
$create_it;
#in the event that the file was never made : (, create it!
} else {
$create_it;
}
}
}
}
}
fclose($create_it);
?>