I'm working in laravel PHP in dx grid dev extreme and I'm having problem while uploading imgae. as image is saved in server but now i want to add image in db by getting users id while row is clicked... how ever I need to update the image in db and frontend as well..enter image description here
Controller:
public function uploadImg(Request $request)
{
if($request['fileInput']) {
$fileName = time().'_'.basename($_FILES["fileInput"]["name"]);
$targetDir = "storage/users/";
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
$allowTypes = array('jpg','png','jpeg','gif');
if(in_array($fileType, $allowTypes)) {
if(move_uploaded_file($_FILES["fileInput"]["tmp_name"], $targetFilePath)) {
return redirect()->back();
} else {
$response['status'] = 'err';
}
} else {
$response['status'] = 'type_err';
}
echo json_encode($response);
}
}
Javascript:
dataField: "avatar",
caption: "Add Image",
width: 200,
alignment: 'center',
formItem: {
visible: false
},
width: 100,
alignment: 'center',
type:"button",
cellTemplate: function (container, options) {
$("<div />")
.text('Upload')
.on('dxclick', function () {
// alert('ok');
$('#fileInput').trigger('click',function() {
id: "users->id",
$("#imageform").onValueChanged(function() {
// uploadUrl: "{{route('upload')}}"
$("#form").submit();
})
});
})
.appendTo(container);
}
},
{
dataField: "avatar",
caption: "Add Image",
alignment: 'center',
formItem: {
visible: false
},
width: 60,
alignment: 'center',
cellTemplate: function(container, options) {
$('<a/ class="uploadfile" data-userid="' + options.data.id + '">').dxButton({
icon: 'upload',
})
// .text('Upload')
.on('dxclick', function() {
// alert($(this).data('userid'));
$('#userid').val($(this).data('userid'));
$('#myModal').modal('show');
})
.appendTo(container);
}