Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel doesn't delete directory

I have a problem deleting a directory.

I'm creating a temporary directory where I unzip a file and I want to delete it when I'm done with it.

My code looks pretty much like this:

$tempPath = storage_path('temp/'.$filemd5.'/');
Storage::makeDirectory($tempPath);
$success = Storage::deleteDirectory($tempPath);
return $success;

It doesn't return anything and the directory doesn't get deleted.

like image 950
Alex Avatar asked Dec 24 '22 14:12

Alex


1 Answers

I think if you remove the trailing backslash from $tempPath, it might work.

$tempPath = storage_path('temp/'.$filemd5);

EDIT:

Okay, I tried different methods and looks like the class File is the most simple one.

File::makeDirectory($path)

and

File::deleteDirectory($path)

More about creating a directory and Deleting a directory

like image 117
Mihkel Allorg Avatar answered Dec 27 '22 21:12

Mihkel Allorg