如何将一个目录移动到PHP中的另一个目录?

时间:2011-12-09 13:36:34

标签: php file

我有两个文件夹

  1. myappdemo.com/VueGuides/services/iclean
  2. myappdemo.com/VueGuides/services/pics
  3. 我需要使用PHP将 iclean 文件夹移到 pics 文件夹中。

    请指导我。

    感谢您提前。

4 个答案:

答案 0 :(得分:29)

使用rename()。请注意,如果它在Web服务器上运行,则Web服务器用户必须有权写入目标目录。

rename("oldpath", "newpath");

// in your case, assuming the script calling rename() 
// resides in the directory above 'myappdemo.com'
rename("myappdemo.com/VueGuides/services/iclean", "myappdemo.com/VueGuides/services/pics/iclean");

// Or use full absolute paths
rename("/path/myappdemo.com/VueGuides/services/iclean", "/path/myappdemo.com/VueGuides/services/pics/iclean");

答案 1 :(得分:3)

如果您担心SEO,我建议您在.htaccess中使用重定向301。

那一定是这样的:

RewriteRule ^/VueGuides/services/iclean  http://myappdemo.com/VueGuides/services/pics  [NS,R=301,L]

答案 2 :(得分:2)

它有一个特定的PHP函数

http://php.net/manual/en/function.rename.php

答案 3 :(得分:0)

在我的情况下,我需要一个不同的解决方案,因为我要将子文件夹的内容移到父文件夹中。 rename在我的实例中不起作用,因为路径相同。

(对于基于Linux的计算机):

exec('mv '.$this->useFolder.'/'.$sub_folder.'/*'.' '.$this->useFolder);

这通过exec使用内置的mv函数。

相关问题