| @@ 175-205 (lines=31) @@ | ||
| 172 | * |
|
| 173 | * @return bool true on success |
|
| 174 | */ |
|
| 175 | public static function rmove($src, $dest) |
|
| 176 | { |
|
| 177 | // Only continue if user is a 'global' Admin |
|
| 178 | if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 179 | return false; |
|
| 180 | } |
|
| 181 | ||
| 182 | // If source is not a directory stop processing |
|
| 183 | if (!is_dir($src)) { |
|
| 184 | return false; |
|
| 185 | } |
|
| 186 | ||
| 187 | // If the destination directory does not exist and could not be created stop processing |
|
| 188 | if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
| 189 | return false; |
|
| 190 | } |
|
| 191 | ||
| 192 | // Open the source directory to read in files |
|
| 193 | $iterator = new \DirectoryIterator($src); |
|
| 194 | foreach ($iterator as $fObj) { |
|
| 195 | if ($fObj->isFile()) { |
|
| 196 | rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 197 | } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
| 198 | // Try recursively on directory |
|
| 199 | self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 200 | // rmdir($fObj->getPath()); // now delete the directory |
|
| 201 | } |
|
| 202 | } |
|
| 203 | $iterator = null; // clear iterator Obj to close file/directory |
|
| 204 | return rmdir($src); // remove the directory & return results |
|
| 205 | } |
|
| 206 | ||
| 207 | /** |
|
| 208 | * Recursively copy directories and files from one directory to another |
|
| @@ 218-245 (lines=28) @@ | ||
| 215 | * |
|
| 216 | * @return bool true on success |
|
| 217 | */ |
|
| 218 | public static function rcopy($src, $dest) |
|
| 219 | { |
|
| 220 | // Only continue if user is a 'global' Admin |
|
| 221 | if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 222 | return false; |
|
| 223 | } |
|
| 224 | ||
| 225 | // If source is not a directory stop processing |
|
| 226 | if (!is_dir($src)) { |
|
| 227 | return false; |
|
| 228 | } |
|
| 229 | ||
| 230 | // If the destination directory does not exist and could not be created stop processing |
|
| 231 | if (!is_dir($dest) && !mkdir($dest, 0755)) { |
|
| 232 | return false; |
|
| 233 | } |
|
| 234 | ||
| 235 | // Open the source directory to read in files |
|
| 236 | $iterator = new \DirectoryIterator($src); |
|
| 237 | foreach ($iterator as $fObj) { |
|
| 238 | if ($fObj->isFile()) { |
|
| 239 | copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 240 | } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
| 241 | self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 242 | } |
|
| 243 | } |
|
| 244 | return true; |
|
| 245 | } |
|
| 246 | } |
|
| 247 | ||