2

I am trying to delete a folder and all its files in Laravel.

I am creating the folder like this:

$filename = $file->getClientOriginalName();
$path = "images/$id/thumbnail/$filename";
Storage::put($path, File::get($file->getRealPath()));

Then in a queue I am trying to delete the folder and all its files by using:

Storage::deleteDirectory("images/$this->id/thumbnail");

But this doesnt delete the folder, and I dont get any errors either

The folder is located in: Storage/app/images

user2722667
  • 8,195
  • 14
  • 52
  • 100
  • This is most likely a duplicate of: http://stackoverflow.com/questions/32552293/laravel-doesnt-delete-directory – Ben D Nov 13 '16 at 19:38
  • @BenD I am never using Storage::makeDirectory(); like in that post – user2722667 Nov 13 '16 at 19:55
  • I suspect that the underlying issue is the same. Have you checked the permissions on that folder to ensure that the webserver has permissions to remove the folder? (what are the permission levels and group/owner?) – Ben D Nov 13 '16 at 21:52

1 Answers1

-2

Refer to my answer here.

SPLFileInfo: get filename without extension

You need to use the Storage facade in order to use the deleteDirectory() method.

<?php

use Illuminate\Support\Facades\Storage;

Storage::deleteDirectory($directory);

Remember, all file paths should be specified relative to the "root" location configured for the disk.

Refer to the Documentation. https://laravel.com/docs/5.3/filesystem#directories

Community
  • 1
  • 1
PHPGrandMaster
  • 358
  • 2
  • 10