【发布时间】:2013-01-02 18:47:04
【问题描述】:
考虑到有问题的文件的创建有点落后于有问题的函数,我尝试运行一个 while 循环以在调用重命名之前争取一点时间。
$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");
在这种配置中,我认为 rename() 只能在 file_exists() 返回 true 时调用,但对于我来说,我无法弄清楚 rename() 是如何/为什么被调用然后返回失败...
PHP 警告: 重命名(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) 没有这样的文件或目录...
【问题讨论】:
-
我不确定这是否能解决问题,但请尝试用 DIRECTORY_SEPARATOR 常量替换正斜杠。
标签: php rename file-exists