如何使用 PHP 移动文件?
代码:
if( file_exists($imageLocation) )
echo "file exists on server";
rename($imageLocation, $imageNewLocation);
输出:
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
我不知道从这里去哪里。
最佳答案
移动文件时,rename()
只能将文件移动到已经存在的文件夹中。它无法即时创建新的父目录。
确保 /home/newloc
存在。如果没有,请使用 mkdir()
来创建它。
关于PHP 重命名() file_exists(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9280095/