4
我目前的情況下上傳的文件是:我做這樣的後續嵌套的重複:AngularJS:通過角JS
$scope.uploadPic = function(file)
{
alert($scope.taskdetails.id); //task_id e.g 21
alert($rootScope.job_id); //job_id e.g 12
file.upload = Upload.upload(
{
url: 'http://localhost/mobile-data/upload_file.php',
data: {
file: file,
task_id: $scope.taskdetails.id,
job_id: $rootScope.job_id
},
});
file.upload.then(function (response) {
$timeout(function() {
file.result = response.data;
});
}, function (response) {
if (response.status > 0)
$scope.errorMsg = response.status + ': ' + response.data;
}, function (evt) {
// Math.min is to fix IE which reports 200% sometimes
file.progress = Math.min(100, parseInt(100.0 * evt.loaded/evt.total));
});
}
但我upload_file.php
我不能接受的值:
task_id: $scope.taskdetails.id,
job_id: $rootScope.job_id
在console.log
他們工作正常。但在服務器端它並沒有收到。這裏是我的代碼upload_file.php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('content-type: application/json; charset=utf-8');
$_POST = json_decode(file_get_contents('php://input'), true);
$task_id = $_POST["task_id"];
$file = $_FILES["file"];
$job_id = $_POST["job_id"];
var_dump($task_id);
var_dump($job_id);
,但是,var_dump
它只能打印空。幫我正確地接收到值..
感謝兄弟。你已經指出了正確的問題.. –
謝謝。不要忘記將此答案標記爲已接受。 –