Thinking creation of the file in question lags a bit behind the offending function, I tried running a while loop to buy a little time before calling rename.
$no_file = 1;
while($no_file && $no_file < 300)
{ // generation of Worksheet.xls may lag behind function -- WAIT FOR IT
if(file_exists($old_path))
{ $no_file = 0;
rename($old_path, $new_path);
} else $no_file++;
}
if($no_file) die("Error: Worksheet.xls not found");
In this configuration, I'm thinking rename() can only be called if file_exists() returns true, but for the life of me I can't figure out how / why then rename() gets called and then fails returning...
PHP Warning: rename(C:\wamp\www\demox/wp-content/plugins/cat-man/store-manager/summary/worksheets/Worksheet.xls,C:\wamp\www\demox/wp-content/plugins/cat-man/store-manager/summary/statements/TESTING/2012/Worksheet.xls) No such file or directory...