Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel delete directory from public

Tags:

php

laravel

How could I delete a directory from the public folder? Right now I try this:

Storage::deleteDirectory($directory);

But that looks in the storage folder?

like image 238
Jamie Avatar asked Apr 05 '16 07:04

Jamie


4 Answers

You can use Illuminate\Filesystem\Filesystem for this. Laravel provides the File facade for easy access:

File::deleteDirectory(public_path('path/to/folder'));

The method will return true if it succeeds, false if it fails.

like image 135
tommy Avatar answered Oct 08 '22 13:10

tommy


You can use this:

 $path = 'upload/pic/foldername/';
 if (\File::exists($path)) \File::deleteDirectory($path);

foldername is deleting with all files in it.

like image 42
Max Avatar answered Oct 08 '22 13:10

Max


To be accessible by Storage you should define the filesystem name in config/filesystems and be sure to have the right permissions to be able to what you want to do.

Then something like Storage::deleteDirectory($directory); assuming that $directory is something you got properly from the corresponding resource.

Read the docs here

like image 5
Muihlinn Avatar answered Oct 08 '22 14:10

Muihlinn


You can use File instead of Storage. Try this one:

File::deleteDirectory(public_path($directory));
like image 2
Alief Avatar answered Oct 08 '22 14:10

Alief