Created
May 2, 2013 19:37
-
-
Save cb99999/5504787 to your computer and use it in GitHub Desktop.
php > copy target set of files to multiple directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/************************* | |
/* copy master files to the farm | |
/*************************/ | |
function full_copy( $source, $target ) | |
{ | |
if ( is_dir( $source ) ) { | |
@mkdir( $target ); $d = dir( $source ); | |
while ( FALSE !== ( $entry = $d->read() ) ) { | |
if ( $entry == '.' || $entry == '..' ) { continue; } | |
$Entry = $source . '/' . $entry; | |
if ( is_dir( $Entry ) ) { | |
full_copy( $Entry, $target . '/' . $entry ); continue; } | |
copy( $Entry, $target . '/' . $entry ); | |
} | |
$d->close(); | |
} else { | |
copy( $source, $target ); | |
} | |
} | |
/************************* | |
/* configure the projects | |
/*************************/ | |
$project_target = $_REQUEST['project']; | |
$password = $_REQUEST['password']; | |
$project_target = 'all'; | |
// check the password | |
if ($password != 'xyz') { | |
echo 'Sorry wrong password.'; | |
} else { | |
// check for a target folder | |
if (!$project_target) { | |
echo 'Where am I copying the template?'; | |
} else { | |
// set the target folder(s) | |
if ($project_target == 'all') { | |
$project = array("folder1","folder2"); | |
} else { | |
$project = array("$project_target"); | |
} | |
/************************* | |
/* set your source directory and theme to be copied | |
/*************************/ | |
$root_dir = 'c:\xampp\htdocs\\'; | |
$source_dir = '2009\\'; | |
$theme_dir = '\wp-content\themes'; | |
$my_theme = '\July8-Remix'; | |
/************************* | |
/* loop: build the source and target | |
/*************************/ | |
foreach ($project as $key => $project_dir) { | |
$my_source = $root_dir . $source_dir . $my_theme; | |
$my_target = $root_dir . $source_dir . $project_dir . $theme_dir . $my_theme; | |
/************************* | |
/* and copy it (with feedback) | |
/*************************/ | |
echo '<h3> '. $project_dir . ' => </h3>'; | |
echo '<ul><li>Copying ' . $my_source .' to: '. $my_target . '</li>'; | |
full_copy( $my_source, $my_target); | |
echo '<li class="confirmed">DONE: View the <a target="blank" href="'.$project_dir.'">'.$project_dir.'</a> blog.</li></ul>'; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment