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