Skip to content

Instantly share code, notes, and snippets.

@rveitch
Last active September 5, 2017 09:50
Show Gist options
  • Save rveitch/e0501f06d68575eba2fa60a3c6afbd50 to your computer and use it in GitHub Desktop.
Save rveitch/e0501f06d68575eba2fa60a3c6afbd50 to your computer and use it in GitHub Desktop.
PHP - Delete Files and Folders (wp directory)
<?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