简体   繁体   中英

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 :

$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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM