[英]Get Content of ng-file-upload POST DATA
I am using ng-file-upload
from Github . 我正在从Github使用
ng-file-upload
。 I have successfully uploaded and added image on both target folder and database. 我已经成功上传并在目标文件夹和数据库上添加了图像。 However, I need a specific data from my client side that will be needed for my query.
但是,我需要从客户端获取查询所需的特定数据。
Controller.js ---- sample snippet of my upload function. 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 ---- relative code on my server side 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
Image ---- from console.log
response
图片 ----来自
console.log
response
The
id
is what I need to get for my query. id
是查询所需的。
How can I get that? 我该怎么办?
file_get_contents
not working for this one, it returns null
. file_get_contents
不适用于此程序,它返回null
。
I got the answer I am looking for. 我得到了我要找的答案。
In my upload function
in my controller
, I changed the key
id
into 'id'
with apostrophe: 在
controller
upload function
中,我用撇号将key
id
更改为'id'
:
data: {
file: Upload.dataUrltoBlob(dataUrl, name),
'id': user[0].id
}
In my php code
, I did this: 在我的
php code
,我这样做:
$id = $_POST['id'];
I got the idea from Github Repo Issues at the last part of the page. 在页面的最后部分,我从Github Repo Issues得到了这个想法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.