PHP - Make dirs and copy files from a URL
I have an array filled with paths looking like this:
library/main/single/list.php
library/article/grid/thumbs.php
library/footer/tiny.php
These files and folders exists on my http://localhost/test/
I also have path that is http://localhost/new/
What I want to do
What I need to do is move the files while keeping the current file structure (with directories intact) to the new location.
The result should be like this
- http://localhost/new/library/main/single/list.p开发者_Go百科hp
- http://localhost/new/library/article/grid/thumbs.php
- http://localhost/new/library/footer/tiny.php
Is there an easy way to do it or do I have to cut every string by its slash?
You could try:
$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);
}
精彩评论