Created
June 18, 2020 16:11
-
-
Save zerobugs-oficial/f018c043bf8062aabbe9b5e6234c1c09 to your computer and use it in GitHub Desktop.
Deletar um diretório com arquivos e subdiretórios usando PHP
This file contains 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 | |
function deletar($pasta){ | |
$iterator = new RecursiveDirectoryIterator($pasta,FilesystemIterator::SKIP_DOTS); | |
$rec_iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST); | |
foreach($rec_iterator as $file){ | |
$file->isFile() ? unlink($file->getPathname()) : rmdir($file->getPathname()); | |
} | |
rmdir($pasta); | |
} | |
// EXEMPLO DE UTILIZACAO | |
deletar('nomeDaPasta'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment