Question

How to delete files using laravel

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


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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');