PHP file_exists 但重命名失败 "No such file or directory..."?

标签 php rename file-exists

<分区>

考虑到有问题的文件的创建有点滞后于有问题的函数,我尝试运行一个 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 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...

最佳答案

它可能告诉你 statements/TESTING/2012/ 不存在。使用 mkdir() 创建这些目录这样它将能够保存文件。

mkdir( 'C:\wamp\www\demox/wp-content/plugins/cat-man/store-manager/summary/statements/TESTING/2012/', 777, true);

关于PHP file_exists 但重命名失败 "No such file or directory..."?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14409415/

相关文章:

php - 提高 Facebook FQL 的性能和可用性

php - 在php中添加一个月

php - Laravel Dropzone TokenMismatchException 大文件

regex - 使用正则表达式查找和重命名文件/文件夹

php - 如何使用 moodle 为管理端和前端设置不同的 css?

python - 从查找文件批量重命名文件名的一部分

r - 如何根据现有模式重命名 R 数据框的列?

c - 当文件实际存在时 open() 文件不存在

azure - Azure 存储函数 object.DeleteIfExists() 在调用时是否检查是否存在?

jquery - 等待jquery ajax请求完成并返回值