【问题标题】:How to add row id of current user in upload如何在上传中添加当前用户的行ID
【发布时间】:2019-04-03 04:54:31
【问题描述】:

我在 dx grid devextreme 中使用 laravel PHP,上传 imgae 时遇到问题。 由于图像保存在服务器中,但现在我想通过在单击行时获取用户 ID 在数据库中添加图像... 我怎么也需要更新数据库和前端中的图像..enter image description here

控制器:

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);
    }
},

【问题讨论】:

标签: javascript laravel laravel-5 devexpress devextreme


【解决方案1】:
 {
               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);
               }

【讨论】:

    猜你喜欢
    • 2022-10-04
    • 2021-10-25
    • 1970-01-01
    • 2022-08-02
    • 2015-06-01
    • 2021-01-12
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    相关资源
    最近更新 更多