2017-06-02 31 views
0

如果我刪除的文件是這樣的:如何刪除laravel 5.3中的文件夾?

$destinationPath = public_path() . DIRECTORY_SEPARATOR . 'img'. DIRECTORY_SEPARATOR . 'products' . DIRECTORY_SEPARATOR . $id; 
$result = File::delete($destinationPath . DIRECTORY_SEPARATOR . $filename); 

它的工作原理

但如果我刪除這樣的文件夾:

$destinationPath = public_path() . DIRECTORY_SEPARATOR . 'img'. DIRECTORY_SEPARATOR . 'products' . DIRECTORY_SEPARATOR . $id; 
File::delete($destinationPath); 

,爲什麼要刪除的文件夾不實在不行

工作?

我該如何解決這個問題?

+4

應先檢查谷歌,得到的解決方案在第一個鏈接:)'刪除目錄laravel'這是我的搜索。 – Webinion

+2

[刪除Laravel中的文件的文件夾]可能的副本(https://stackoverflow.com/questions/41207731/deleting-a-folder-with-files-in-laravel) – JazzCat

回答

2

您正試圖使用​​錯誤的方法。您需要使用deleteDirectory而不是delete

$destinationPath = public_path('img/products/'. $id); 
File::deleteDirectory($destinationPath); 
+0

現在,它已經解決 –

+0

哪一個類需要爲此包括在內? –

相關問題