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