I am saving an image to public folder and now I want to display it inside a defined div class="logo" how can that be achieved?
Controller:
public function testing(Request $request) {
if($request->hasFile('img'));
{
$image = Input::file('img');
$filename = time() . '.' . $image->getClientOriginalExtension();
$path = public_path('images/' . $filename);
Image::make($image->getRealPath())->resize(200, 200)->save($path);
$file = $request->file('img');
return response()->file($file);
}
}
JS:
function submitImage(){
var fd = new FormData($("#upload_form")[0]);
fd.append( 'img', $('#img') );
$.ajax({
url:'template',
data: fd,
dataType:'json',
async:false,
type:'post',
processData: false,
contentType: false,
});
}
Blade:
<form id="upload_form" action="" enctype="multipart/form-data" role="form" method="POST">
<input type="hidden" name="_token" value="">
<input name="img" id="img" class="form-control filestyle margin images" data-input="false" type="file" data-buttonText="Upload Logo" data-size="sm" data-badge="false" onchange="submitImage();" />
</form>
<div class="logo">
<img class="images" id="image" src="#" alt="Your Logo"/>
</div>
So I want to change src="#" to a path where image has been saved such as "C://xampp/htdocs/laravel/public/image/1.jpg"
via Przemek