php 如何在php中将一个目录移动到另一个目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8446247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:43:54  来源:igfitidea点击:

how to move one directory to another directory in php?

phpfile

提问by Ajay

I have two folders

我有两个文件夹

  1. myappdemo.com/VueGuides/services/iclean
  2. myappdemo.com/VueGuides/services/pics
  1. myappdemo.com/VueGuides/services/iclean
  2. myappdemo.com/VueGuides/services/pics

I need to move icleanfolder into picsfolder using PHP.

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

please guide me.

请指导我。

Thanks for advance.

感谢您的提前。

回答by Michael Berkowski

Use rename(). Note that if this runs on a web server, the web server user must have access to write to the target directory.

使用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");

回答by josegil

If you are worried about SEO i recommend you using redirects 301 in your .htaccess.

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

That must be something like that:

那一定是这样的:

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

回答by spider

There's a specific PHP function for it

它有一个特定的 PHP 函数

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

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