Reputation: 179
I'm trying to delete a file in laravel 5 application . My controller code is
public function deleteImages(){
$image = public_path() . '/uploads/images/'.Input::get('image');
Storage::Delete($image);
}
i'm getting an error message like
local.ERROR: exception 'League\Flysystem\FileNotFoundException' with message 'File not found at path: var/www/html/wonders/uploads/images/Copy1Copy1Kuruva-Islands.jpg' in /var/www/html/wonders/vendor/league/flysystem/src/Filesystem.php:381
But the file is really existing and the path is correct. But i'm wondering why it shows such an error.
Upvotes: 4
Views: 1904
Reputation: 272
Assuming that your code is correct: have you checked the ownership and permissions of the file you wish to delete? Maybe your web server user does not have the proper permissions to manipulate said file.
I am not sure what platform you are working on, but in a debian / apache2 environment, the file owner should generally be www-data and the permissions should be 644.
Upvotes: 0
Reputation: 147
In the documentation I found:
When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt:
Storage::disk('local')->put('file.txt', 'Contents');
The way I see it you can't use Storage::delete
here because you are trying to delete a file in your public folder.
Try one of these that I found on Laravel Recipies:
// Delete a 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);
I've added a leading \ because you are using Laravel 5.
Upvotes: 2
Reputation:
try to use the File::delete($filename);
Or refer to these link http://laravel-recipes.com/recipes/133/deleting-a-file
https://laracasts.com/discuss/channels/general-discussion/l5-how-to-delete-a-file-using-filesystem
Upvotes: 0