【问题标题】:PHP rename() file_exists()PHP 重命名()文件存在()
【发布时间】:2012-03-06 00:14:52
【问题描述】:

如何使用 PHP 移动文件?

代码:

if( file_exists($imageLocation) )
  echo "file exists on server";

rename($imageLocation, $imageNewLocation);

输出:

文件存在于服务器上 警告:rename(/home/images/file1.jpg,/home/newloc/renamed.jpg) [function.rename]: No such file or directory in /home/apps/images/add.php on line 81

我不知道从这里去哪里。

【问题讨论】:

    标签: php rename


    【解决方案1】:

    移动文件时,rename() 只能将它们移动到已经存在的文件夹中。它不能即时创建新的父目录。

    确保/home/newloc 存在。如果没有,请使用mkdir() 创建它。

    【讨论】:

    • rename() can't create folders. It can only move files to an existing folder. 这充其量是误导。PHP: rename - Manual 特别指出 >rename — 重命名文件或目录如果它已经存在...我们不会 rename我们会这样做吗?
    • @WallabyKid 真实,澄清
    猜你喜欢
    • 2015-03-18
    • 2014-08-09
    • 2012-04-18
    • 2014-09-09
    • 2014-01-20
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 2015-01-11
    相关资源
    最近更新 更多