| @@ 222-252 (lines=31) @@ | ||
| 219 | * | |
| 220 | * @return bool true on success | |
| 221 | */ | |
| 222 | public static function rmove($src, $dest) | |
| 223 |     { | |
| 224 | // Only continue if user is a 'global' Admin | |
| 225 |         if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { | |
| 226 | return false; | |
| 227 | } | |
| 228 | ||
| 229 | // If source is not a directory stop processing | |
| 230 |         if (!is_dir($src)) { | |
| 231 | return false; | |
| 232 | } | |
| 233 | ||
| 234 | // If the destination directory does not exist and could not be created stop processing | |
| 235 |         if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { | |
| 236 | return false; | |
| 237 | } | |
| 238 | ||
| 239 | // Open the source directory to read in files | |
| 240 | $iterator = new \DirectoryIterator($src); | |
| 241 |         foreach ($iterator as $fObj) { | |
| 242 |             if ($fObj->isFile()) { | |
| 243 |                 rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); | |
| 244 |             } elseif (!$fObj->isDot() && $fObj->isDir()) { | |
| 245 | // Try recursively on directory | |
| 246 |                 self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); | |
| 247 | // rmdir($fObj->getPath()); // now delete the directory | |
| 248 | } | |
| 249 | } | |
| 250 | $iterator = null; // clear iterator Obj to close file/directory | |
| 251 | return rmdir($src); // remove the directory & return results | |
| 252 | } | |
| 253 | ||
| 254 | /** | |
| 255 | * Recursively copy directories and files from one directory to another | |
| @@ 265-293 (lines=29) @@ | ||
| 262 | * | |
| 263 | * @return bool true on success | |
| 264 | */ | |
| 265 | public static function rcopy($src, $dest) | |
| 266 |     { | |
| 267 | // Only continue if user is a 'global' Admin | |
| 268 |         if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { | |
| 269 | return false; | |
| 270 | } | |
| 271 | ||
| 272 | // If source is not a directory stop processing | |
| 273 |         if (!is_dir($src)) { | |
| 274 | return false; | |
| 275 | } | |
| 276 | ||
| 277 | // If the destination directory does not exist and could not be created stop processing | |
| 278 |         if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { | |
| 279 | return false; | |
| 280 | } | |
| 281 | ||
| 282 | // Open the source directory to read in files | |
| 283 | $iterator = new \DirectoryIterator($src); | |
| 284 |         foreach ($iterator as $fObj) { | |
| 285 |             if ($fObj->isFile()) { | |
| 286 |                 copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); | |
| 287 |             } elseif (!$fObj->isDot() && $fObj->isDir()) { | |
| 288 |                 self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); | |
| 289 | } | |
| 290 | } | |
| 291 | ||
| 292 | return true; | |
| 293 | } | |
| 294 | } | |
| 295 | ||