FTP 및 해당 폴더에 포함 된 모든 하위 폴더 및 파일을 사용하여 폴더를 삭제하는 기능을 추가하려고합니다.FTP 연결의 폴더 및 모든 파일 삭제
이렇게 재귀 함수를 만들었으므로 논리가 옳다는 느낌이 들지만 아직 작동하지 않습니다.
몇 가지 테스트를했는데 경로가 빈 폴더 또는 파일 일 경우 처음 실행할 때 삭제할 수 있지만 하나의 파일 또는 하나의 빈 하위 폴더가있는 폴더 인 경우 삭제할 수 없습니다 . 그래서 그것은 폴더 (들)을 통과하고 삭제 기능을 사용하여 문제가 될 것 같습니다.
아이디어가 있으십니까?
function ftpDelete($directory)
{
if(empty($directory))//Validate that a directory was sent, otherwise will delete ALL files/folders
return json_encode(false);
else{
global $conn_id;
# here we attempt to delete the file/directory
if(!(@ftp_rmdir($conn_id,$directory) || @ftp_delete($conn_id,$directory)))
{
# if the attempt to delete fails, get the file listing
$filelist = @ftp_nlist($conn_id, $directory);
# loop through the file list and recursively delete the FILE in the list
foreach($filelist as $file)
ftpDelete($file);
#if the file list is empty, delete the DIRECTORY we passed
ftpDelete($directory);
}
else
return json_encode(true);
}
};
디렉토리를 수행하거나의 당신은 하위 디렉토리입니다 공백을 삭제하려고합니까? –
파일이나 폴더에 공백이 없어야합니다. 그냥 알파 문자. – JimmyJammed
해당 디렉토리에서 파일 시스템 권한을 사용하여 디렉토리를 삭제할 수 있습니까? – sarnold