dtn55928
dtn55928
2012-02-14 16:02

PHP rename()file_exists()

已采纳

How can I use PHP to move a file?

Code:

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

rename($imageLocation, $imageNewLocation);

Output:

file exists on server Warning: 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

I don't know where to go from here.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongxingji3882 dongxingji3882 9年前

    When moving files, rename() can only move them to a folder that already exists. It can not create new parent directories on the fly.

    Make sure /home/newloc exists. If it doesn't, use mkdir() to create it.

    点赞 评论 复制链接分享

相关推荐