Skip to content

How to delete file(s) in Laravel 5

Last updated on December 2, 2022

Deleting files from the file system is a very common task nowadays and it can be done in several ways.

We generally use PHP’s built-in unlink() function to delete files from the file system, there is nothing wrong with using it. But we gonna use Laravel’s File::delete() method because it is giving the option to delete multiple files at once.

Note: It is always better to check the existence of the file with File::exists() before attempting to delete it.

Delete single file

File::delete($filename);

Delete Multiple files

File::delete($file1, $file2, $file3)

Delete an array of files

 $files = array($file1, $file2);
 File::delete($files);
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments