Laravel Delete File
NickName:BangularTK Ask DateTime:2016-11-08T15:37:04

Laravel Delete File

I have a test.txt file in my Laravel public folder which I simply want to delete from my controller by using

unlink('public/test.txt');

Whenever I try to run, I keep getting a 'file not found' error

ErrorException in WidgetController.php line 32: unlink('public/test.txt'): No such file or directory

What seems to be the problem here?

Copyright Notice:Content Author:「BangularTK」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40481382/laravel-delete-file

Answers
S.I. 2016-11-08T08:14:49

Use app_path to delete the file. More about the paths here\n\n$file_path = app_path(\"test.txt\"); // app_path(\"public/test.txt\");\nif(File::exists($file_path)) File::delete($file_path);\n",


More about “Laravel Delete File” related questions

How to delete a file in laravel 4

I'm using laravel 4 and I need to change an uploaded image, I have it in: Public --uploads ---news ----id_news.jpg When editing the new's I want to make a change image form, but how could I delet...

Show Detail

Delete permissions for uploaded file in Laravel

I have a directory called photos with read, write & delete permissions for itself and it's enclosed items. I use the Laravel's method move() in order to upload the file inside the directory i

Show Detail

Laravel Delete File

I have a test.txt file in my Laravel public folder which I simply want to delete from my controller by using unlink('public/test.txt'); Whenever I try to run, I keep getting a 'file not found' er...

Show Detail

Laravel delete file in app folder (root)

How to delete files from Laravel app directory (not the public directory but the one in the root)? I tried : \Storage::Delete('App\file.php'); \Storage::Delete('\App\file.php'); \File::Delete('Ap...

Show Detail

Laravel-Mediable - delete media together with file

I've been reading the Laravel-Mediable docs about deleting media. However, I'm a bit confused on how to delete a specific media, together with its file without using query builder. As per the docs...

Show Detail

Laravel 5.1 - Unable to delete file

I have the following code: Storage::delete(public_path($file->path)); But I get error: File not found at path: C:\wamp\www\laravel\acme\public\img/logos/1486846424_acme.gif When I check the

Show Detail

Angular + Laravel Delete File

I'm building a REST-full web-app using Laravel 5.2 (for the back-end) and AngularJS for the font-end. I connect to the Laravel back-end by the use of an API. Now I have stumbled upon the following

Show Detail

Issue on delete a file in laravel 5

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::

Show Detail

Delete file using crontab with Laravel 4

I'm trying to delete a file using Laravel 4, but, with crontab. I have created a "costume_command" with Artisan (notify). And in the "fire" method, that will execute when the command is used in cm...

Show Detail

Laravel 5 File Delete Error

There is an issue related to my laravel 5 web application regarding the file deletion. I want to delete an entry from my table with corresponding image file. Here is my table structure. Schema::...

Show Detail