繁体   English   中英

获取ng-file-upload POST数据的内容

[英]Get Content of ng-file-upload POST DATA

我正在从Github使用ng-file-upload 我已经成功上传并在目标文件夹和数据库上添加了图像。 但是,我需要从客户端获取查询所需的特定数据。

Controller.js ----我的上传功能的示例代码段。

$scope.upload = function (dataUrl, name) {
        Upload.upload({
            url: 'php/profile-pic.php',
            method: 'POST',
            transformRequest: angular.identity,
            headers: {
                'Content-Type': undefined,
                'Process-Data' : false
            },
            data: {
                file: Upload.dataUrltoBlob(dataUrl, name),
                id: user[0].id
            },

        }).then(function (response) {

            $timeout(function () {
                $scope.result = response.data;
            });
            console.log(response);
        }, function (response) {
            if (response.status > 0) $scope.errorMsg = response.status 
                + ': ' + response.data;

                console.log(response);
        }, function (evt) {
            $scope.progress = parseInt(100.0 * evt.loaded / evt.total);
        });
    }

PHP ----服务器端的相对代码

        $postdata = file_get_contents("php://input");
        $data = json_decode($postdata);
        // $id = $data->id;
        echo json_encode($data) // returns null

        if(!empty($_FILES))  
        {  
            $filename = $_FILES['file']['name'];
            $destination = '/../images/' . $filename; 
             if(move_uploaded_file( $_FILES['file']['tmp_name'] , PATH . $destination ))  
             {  
                  $insertQuery = "UPDATE tblusers SET image = ".$_FILES['file']['name']." WHERE id='???'"; // ??? = the specific data that I need

图片 ----来自console.log response HTTP响应 id是查询所需的。

我该怎么办? file_get_contents不适用于此程序,它返回null

我得到了我要找的答案。

controller upload function中,我用撇号将key id更改为'id'

data: {
        file: Upload.dataUrltoBlob(dataUrl, name),
        'id': user[0].id
      }

在我的php code ,我这样做:

$id = $_POST['id'];

在页面的最后部分,我从Github Repo Issues得到了这个想法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM