Last active
September 5, 2017 09:50
-
-
Save rveitch/e0501f06d68575eba2fa60a3c6afbd50 to your computer and use it in GitHub Desktop.
PHP - Delete Files and Folders (wp directory)
This file contains hidden or 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 | |
$dir = '/Applications/AMPPS/www/areavoices/wp-content/uploads/sites/47'; | |
if ( is_dir( $dir ) ) { | |
$it = new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS ); | |
$files = new RecursiveIteratorIterator( $it, RecursiveIteratorIterator::CHILD_FIRST ); | |
foreach ( $files as $file ) { | |
if ( $file->isDir() ) { | |
rmdir( $file->getRealPath() ); | |
} else { | |
unlink( $file->getRealPath() ); | |
} | |
} | |
rmdir( $dir ); | |
} else { | |
echo 'Error: Path is not a valid directory.'; | |
} | |
echo 'Nuked That Directory.'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment