嘗試添加使用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);
}
};
不目錄或任何的那就是你的子目錄試圖刪除包含空格? – 2011-12-15 00:49:43
文件或文件夾不能有空格。只是字母字符。 – JimmyJammed 2011-12-15 00:59:22
對相關目錄的文件系統權限是否允許刪除目錄? – sarnold 2011-12-15 01:49:43