Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Builds php files on xampp localhost then outputs them to a build folder (as HTML, eventually)
- //Written by Kris with a K
- //Recursively delete dir/contents
- //Thanks to holger1 at php.net for code
- function rrmdir($dir) {
- if (is_dir($dir)) {
- $objects = scandir($dir);
- foreach ($objects as $object) {
- if ($object != "." && $object != "..") {
- if (filetype($dir."/".$object) == "dir")
- rrmdir($dir."/".$object);
- else
- unlink ($dir."/".$object);
- }
- }
- reset($objects);
- rmdir($dir);
- }
- }
- //Recursively glob dir/contents
- //Thanks to StackOverflow community for assistance
- function r2glob($dir, $ext = "*") {
- $files = glob($dir . "\\" . $ext);
- foreach($files as $subDir)
- {
- if (is_dir($subDir . "\\"))
- $files = array_merge($files, r2glob($subDir));
- }
- return $files;
- }
- //Checks to see if a filepath ends in a file-ext or dir name
- function is_dir_path($path) {
- $levels = explode("\\", $path);
- $last = $levels[sizeof($levels) - 1];
- if (sizeof(explode(".", $last)) > 1)
- return false;
- else
- return true;
- }
- $localroot = "C:\\xampp\htdocs\intranet\\";
- $localbuild = "C:\\xampp\htdocs\intranet\build\\";
- $hosted = "https:\\\\localhost\intranet\\";
- echo $localroot . "<br>";
- echo $localbuild . "<br>";
- echo $hosted . "<br>";
- // sterilize build dir
- rrmdir($localbuild);
- // get build files
- $paths = r2glob(dirname(__FILE__));
- // output build files
- foreach($paths as $path)
- {
- echo "<br>";
- $path = str_replace($localroot, "", $path);
- $source = $hosted . $path;
- $dest = $localbuild . $path;
- if (is_dir_path($dest))
- {
- mkdir($dest, 0755, true);
- echo "Make folder $source at $dest. <br>";
- }
- else
- {
- copy($source, $dest);
- echo "Copy $source to $dest. <br>";
- }
- }
- ?>
Add Comment
Please, Sign In to add comment