Php 如何将一个目录移动到另一个目录?

Php 如何将一个目录移动到另一个目录?,php,file,Php,File,我有两个文件夹 myappdemo.com/VueGuides/services/iclean myappdemo.com/VueGuides/services/pics 我需要使用PHP将iclean文件夹移动到pics文件夹中。它有一个特定的PHP函数 使用。请注意,如果此操作在web服务器上运行,则web服务器用户必须具有写入目标目录的权限 rename("oldpath", "newpath"); // in your case, assuming the script calli

我有两个文件夹

  • myappdemo.com/VueGuides/services/iclean

  • myappdemo.com/VueGuides/services/pics


  • 我需要使用PHP将iclean文件夹移动到pics文件夹中。

    它有一个特定的PHP函数

    使用。请注意,如果此操作在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");
    

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

    那一定是这样的:

    RewriteRule^/VueGuides/services/icleanhttp://myappdemo.com/VueGuides/services/pics  [NS,R=301,L]
    
    在将子文件夹内容移动到父文件夹时,我需要一个不同的解决方案<代码>重命名在我的实例中不起作用,因为路径相同

    (对于基于Linux的机器):

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


    这通过exec使用内置的
    mv
    功能。

    这是一次性问题吗?或者,您将定期将其作为web应用程序的一部分进行。如果您正在寻找用PHP编写的文件管理器,可以使用:hi-put-code-i-get-Warning:rename(www.myappdemo.com/VueGuides/services/iclean,www.myappdemo.com/VueGuides/services/pics)[function.rename]:在线/home/myappdemo/myappdemo.com/VueGuides/services/getZip.php中没有此类文件或目录55@user816891很明显,您使用了错误的路径名称。您的路径是
    /home/myappdemo/myappdemo.com/…
    ,您已指定
    www.myappdemo.com/…
    。您需要使用完全正确的文件路径。这是一个文件路径,而不是URL路径……上面的示例不是将目录'iclean'重命名为'pics'(完全替换'pics'目录)吗?任务是将“iclean”移动到“pics”中,因此是否应该重命名它(“myappdemo.com/VueGuides/services/iclean”、“myappdemo.com/VueGuides/services/pics/iclean”)@是的,应该是。在Unix命令行上,一个
    mv
    会将其放入已经存在的目标目录中。PHP
    rename()
    确实会替换它,但如果目标目录不是空的,就会失败。