我有一个充满路径的数组,如下所示:
library/main/single/list.php
library/article/grid/thumbs.php
library/footer/tiny.php
这些文件和文件夹存在于我的 http://localhost/test/
我也有 http://localhost/new/的路径
我想做什么
我需要做的是将文件移动到新位置,同时保持当前文件结构(目录完好无损)。
结果应该是这样的
- http://localhost/new/library/main/single/list.php
- http://localhost/new/library/article/grid/thumbs.php
- http://localhost/new/library/footer/tiny.php
有没有一种简单的方法可以做到这一点,或者我必须用斜杠切割每根字符串?
你可以试试:
$from = './test/'; //replace with absolute path if better
$to = './new/';
$paths = array('library/main/single/list.php', 'library/article/grid/thumbs.php', 'library/footer/tiny.php');
$dirs = array();
foreach( $paths as $path ) {
$pathinfo = pathinfo($to.$path);
if (!in_array($pathinfo['dirname'], $dirs) && !file_exists($pathinfo['dirname']) && mkdir($pathinfo['dirname'], 0777, true))
$dirs[] = $pathinfo['dirname'];
copy($from.$path, $to.$path);
}