Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

How to Delete uploaded file in Laravel

 

The public_path function returns the fully qualified path to the public directory and the base_path function returns the fully qualified path to the project root.

So if you want to reach a file in public folder you can use public_path() like this:

unlink(public_path("test.txt"));

You can also use File:delete instead of unlink like this:

use File;
File::delete(public_path("test.txt"));

// Delete multiple files
File::delete($file1, $file2, $file3);

// Delete an array of files
$files = array($file1, $file2);
File::delete($files);

 

Example with storage:

  1. Using the default local storage you need to specify public subfolder:
Storage::delete('public/'.$image_path);
  1. Use public storage directly:
Storage::disk('public')->delete($image_path);

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon