Forum Moderators: coopster

Message Too Old, No Replies

rename() and filesize() Question

My code is not working

         

boxfan

10:17 pm on Feb 7, 2008 (gmt 0)

10+ Year Member



Hi,

I have the following code


$file = "/home/public_html/orders.txt";
if (file_exists($file)) {
if (filesize($file) > 5242880) {
rename($file, "/home/public_html/orders_".date(Ymd).".txt");
if ($ifarray == 1) {
$string = join('', $data);
$fr = fopen($file,'a');
fputs($fr, $string);
} else {
$fr = fopen($file,'a');
$data = $data."\n";
fputs($fr, $data);
}
fclose($fr);
} else {
if ($ifarray == 1) {
$string = join('', $data);
$fr = fopen($file,'a');
fputs($fr, $string);
} else {
$fr = fopen($file,'a');
$data = $data."\n";
fputs($fr, $data);
}
fclose($fr);
}
} else {
$fr = fopen($file,'a');
$data = $data."\n";
fputs($fr, $data);
fclose($fr);
}
}

The filesize

echo filesize($file);

is currently 6187229

For some reason I am not able to change the file name once it exceeds the target filesize.

Any ideas?

Thanks.

Demaestro

11:12 pm on Feb 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Instead of renaming it you can try pulling the file into memory... then create a new file using the old file data and give it the new name then delete the old file or copy it to an archive somewhere then delete it.