Last active
July 17, 2018 11:24
-
-
Save koivunen/120d6cea15112fe90eab09176aab4694 to your computer and use it in GitHub Desktop.
Chown files to www-data when you do not have access to do it yourself
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 | |
$dest = "../public_html_chowned"; | |
$source = "../public_html"; | |
error_reporting(-1); | |
ini_set('display_errors', 'On'); | |
ob_end_flush(); | |
ob_implicit_flush(); | |
echo "Starting...\n"; | |
var_dump ("timelimit",set_time_limit(3600)); | |
mkdir($dest, 0770); | |
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) | |
{ | |
if ($item->isDir()) { | |
mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0770); | |
} else { | |
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName()); | |
chmod($dest, 0770); | |
unlink($item); | |
} | |
} | |
// Delete source | |
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) | |
{ | |
if ($item->isDir()) { | |
rmdir($item); | |
} else { | |
# ??? | |
} | |
} | |
// Move back to in place | |
var_dump (rmdir($source)); | |
var_dump (rename($dest,$source)); | |
echo "\nDONE!"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment