Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 delete and upload another file. I am using:

Input::file('img')->move('uploads/news', $id.'_news.jpg');

The problem it's that it doesn't work, it's not replacing the file, so how could I delete The image so I could upload again.

In laravel 3 I only used:

File::delete('path/to/file');

But I don't see anything about removing files in laravel docs.

like image 229
Chachoo Aguirre Avatar asked Jun 05 '13 23:06

Chachoo Aguirre


2 Answers

I think you should append public_path() to file names , to get real file path, like this

File::delete(public_path().$id.'_news.jpg');
like image 121
Abbas Palash Avatar answered Oct 11 '22 02:10

Abbas Palash


There is still the delete method in Laravel 4:
src/Illuminate/Filesystem/Filesystem.php

otherwise just use good old unlink()!?

like image 24
ChrisG Avatar answered Oct 11 '22 02:10

ChrisG