Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AngularJS:通过AngularJS上传文件_Php_Angularjs - Fatal编程技术网

Php AngularJS:通过AngularJS上传文件

Php AngularJS:通过AngularJS上传文件,php,angularjs,Php,Angularjs,我目前的情况是:我做了如下嵌套重复: $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_f

我目前的情况是:我做了如下嵌套重复:

$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\u 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\u dump
上,它只打印空值。帮助我正确接收值。

在php文件中删除解码行,即:

$_POST = json_decode(file_get_contents('php://input'), true);
您不需要解码,因为您没有将数据接收到JSON编码的数组中