I need help .(
Jul 25, 2018
3
Level 1
Help in this code to upload and delete image on public folder
Hello everyone! How are you?
I'm having a hard time uploading a photo and deleting it.
Sending is okay, but when I delete the image and send a new one the old photo that is returning and not the new one.
What am I doing:
I use the webcam to take the photo and in base64 convert with the base64_decode of laravel.
But deleting I think that just deleting already solves, but it is not!
Functions:
public function saveImagem($img,$id,$path)
{
//$img = base64_decode($img);
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$imgName = $id.'.png';
$path = public_path().'/uploads/'.$path.'/'.$imgName;
\File::put($path, base64_decode($img));
return $imgName;
}
public function destroyImagem($photo, $path)
{
$imgName = $photo.'.png';
$fileDir = public_path().'/uploads/'.$path.'/';
if(\File::exists($fileDir . $imgName)){
\Storage::delete($fileDir . $imgName);
return true;
}
return false;
}
Can someone help me?
Thanks in advance!
Please or to participate in this conversation.