Hey guys, Im using the Intervention image to allow users to upload their images - this part works.
When I want to update images, is there a way to delete the "old" picture and replace it with the new one?
Here is my code:
$listing->image = Input::get('image');
$image = Input::file('image');
$filename = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();
$path = public_path('images/listings/'.$filename);
Image::make($image->getRealPath())->fit(400)->save($path);
$listing->image = 'images/listings/'.$filename;
Thanks in advance!
You have two options that would probably work:
first when a new file is uploaded, just write it with the same name. That would just overwrite it.
or, you'd need to get the old file, call delete on it and then just do the do in the same way.
Overwrite the old file in the same location.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community