Deleting a file from storage does not delete an image

Pouya

I'm using Laravel 5.8 and I wanted to delete an image from storage directory.

Basically the images is placed at this dir:

/storage/app/public/laboratories/labs/21/pics

And I tried running this method:

public function removeAzPic($lab,$azpic)
    {
        $destinationPath = storage_path("laboratories/labs/$lab/pics/$azpic");
        
        Storage::delete($destinationPath);

        return redirect()->back();

    }

But the problem is it does not delete the file from storage!

So what's going wrong here? How can I solve this issue?

Tural Rzaxanov

You can add this function to the helper.php for to delete files/directories recursively:

Function will help you to delete files at the moment. If you want to delete directories change if ( is_dir($full) ) { to if ( is_file($full) ) {


public static function rrmdir($src = null) {

        if(!is_dir($src)) return false;

        $dir = opendir($src);
        while(false !== ( $file = readdir($dir)) ) {
            if (( $file != '.' ) && ( $file != '..' )) {
                $full = $src . '/' . $file;
                if ( is_dir($full) ) {
                    self::rrmdir($full);
                }  else {
                    @unlink($full);
                }
            }
        }
        closedir($dir);
        rmdir($src);

        return true;
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Storage::delete not deleting the file. The path is correct and the file permissions are correct

Deleting file from Firebase Storage using URL

Deleting file from Firebase storage causes crash

android deleting a file from internal storage

Deleting file from app's private storage

Does deleting a file from my computer also delete it from Ubuntu One?

Unable to delete file from storage

Deleting a file and delete its name from a list

Laravel 5.3: delete image from storage

How to delete temporary image from internal storage

How to delete image from Firebase Storage?

Storage disk delete image from db

How to delete image from Firebase storage by url?

How to delete a file from TFS repository without deleting local file

Deleting a managedObject from table but how to delete attached image?

how to delete a file or a photo from the folder when deleting it from database?

Cloud functions: Delete file from storage

Delete file in cloud storage from cloud functions

How to delete a file from the local storage in Flutter?

Power Automate, Delete file from blob storage

SQLALCHEMY deleting Association Object does not delete it from the parent and child

cordova load image file from device storage

How to delete a file from storage using file's path?

How i can delete image from Firebase Storage

How to Delete Image from Firebase cloud Storage - REACT

android - Is possible delete a file from external/internal storage from PHP?

Cannot delete file with 'Storage::delete'

Bug from delete image file using android

cannot delete the image from the directory but the data succeed deleting from database in codeigniter