[英]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
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.