Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

delete previous uploaded image when update laravel

        if($request->file('image'))
        {
            //to delete the prevous uploaded image
            @unlink(public_path('backend/uploads/profile/'.$user->image));
            //make the image name. here we are making name with current time
            $imageName = time().'.'.$request->image->extension();
            //time to upload to directroy you choose
            $request->image->move(public_path('backend/uploads/profile'), $imageName);
            //now save the image name to database
            $user['image'] = $imageName;
        }
        //finally time to save all things to database
        $user->save();
 
PREVIOUS NEXT
Tagged: #delete #previous #uploaded #image #update #laravel
ADD COMMENT
Topic
Name
2+2 =