[英]How can I delete folder in laravel 5.3?
If I delete file like this : 如果我这样删除文件:
$destinationPath = public_path() . DIRECTORY_SEPARATOR . 'img'. DIRECTORY_SEPARATOR . 'products' . DIRECTORY_SEPARATOR . $id;
$result = File::delete($destinationPath . DIRECTORY_SEPARATOR . $filename);
It works 有用
But if I delete folder like this : 但是,如果我删除这样的文件夹:
$destinationPath = public_path() . DIRECTORY_SEPARATOR . 'img'. DIRECTORY_SEPARATOR . 'products' . DIRECTORY_SEPARATOR . $id;
File::delete($destinationPath);
It does not work 这是行不通的
Why delete folder does not work? 为什么删除文件夹不起作用?
How can I solve this problem? 我怎么解决这个问题?
You are attempting to use the wrong method. 您正在尝试使用错误的方法。 You need to use
deleteDirectory
and not delete
: 您需要使用
deleteDirectory
而不是delete
:
$destinationPath = public_path('img/products/'. $id);
File::deleteDirectory($destinationPath);
If you want to delete folder with files than use:- 如果要删除文件夹而不是使用以下文件:-
use Illuminate\Support\Facades\Storage;
Storage::deleteDirectory($public_path);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.