문제:
디렉토리와 그 전체 내용을 효과적으로 삭제하는 방법 , 모든 하위 디렉터리 및 관련 파일 포함 PHP?
답변:
이 반복적인 디렉터리 삭제 작업을 해결하기 위해 rmdir 매뉴얼 페이지의 사용자 기여 방법을 활용합니다.
function rrmdir($dir) { // Verify if the specified path is a valid directory if (is_dir($dir)) { // Retrieve a list of files and subdirectories within the directory $objects = scandir($dir); // Iterate through each item in the directory foreach ($objects as $object) { // Exclude hidden files and directories (dot files) if ($object !== "." && $object !== "..") { // If the item is a directory, recursively delete it if (is_dir($dir . DIRECTORY_SEPARATOR . $object) && !is_link($dir . "/" . $object)) { rrmdir($dir . DIRECTORY_SEPARATOR . $object); } else { // Delete the item if it's a file unlink($dir . DIRECTORY_SEPARATOR . $object); } } } // Once all items within the directory have been removed, remove the directory itself rmdir($dir); } }
위 내용은 PHP에서 디렉토리와 그 내용을 어떻게 재귀적으로 삭제할 수 있습니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!