Report this

What is the reason for this report?

How to delete files using laravel

Posted on October 23, 2020

I am using DigitalOcean Spaces as a configured disk in Laravel and was having a problem with deletion of file using the following codes:

Source: https://laravel.com/docs/5.5/filesystem#deleting-files

Storage::disk('spaces')->delete('foldername/'.$fileName);

I have no problem uploading photos but I wanna have an option of replacing a file when a new one is uploaded. I tried this using my local disk and it worked, but when using do_spaces disk, nothing happens. I can even check that the file exists by using Storage::disk('spaces')->exists('foldername/'.$fileName); before trying to delete.

I am not sure if this is an issue in do spaces or is delete function like above is not supported here. Any idea what I’m doing wrong? Thanks



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

The delete file storage method within Laravel does work with Digital Ocean spaces. We use it on our projects. The only thing I can think of is you are not including the full path of the file, including the extension to delete it.

Try deleting the file without the variable and see if that works. If so, it leads me to believe something is wrong with your $filename variable.

Storage::disk('do')->delete('folder/file.txt');

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.