title: Angular/PHP: upload file data in $_POST, not $_FILES
body: <p>I'm using <strong>AngularJS v1.6.1,</strong> <strong>Apache 2.4.10</strong> on Debian with <strong>PHP 5.6.24</strong> and I'm trying to upload a file to my server using <code>$http</code> POST service.
  On my <code>php.ini</code>, max file size is set to 8Mo, max post size too, upload file is on, and memory size limit is set to 128Mo.</p>
  
  <p><strong>Form:</strong></p>
  
  <pre><code>&lt;input type="file" accept="application/pdf" id="uploadOT" max-files="1" ng-model="uploadOT" name="uploadOT" valid-file required ng-class="{'md-input-invalid':uploadForm.uploadOT.$error.validFile}" /&gt;
  </code></pre>
  
  <p><strong>Angular directive:</strong> (when input content change, get a FileReader object and send file)</p>
  
  <pre><code>myModule.directive('validFile', function() {
      return {
          require:    'ngModel',
          link:       function(scope, elt, attrs, ctrl) {
              ctrl.$setValidity('validFile', elt.val() !== '');
              elt.bind('change', function() {
  
                  var file = document.getElementById('uploadOT').files;
                  var reader = new FileReader();
                  reader.onload = function(e) {
                      scope.sendFile(reader, scope.id);
                  };
                  scope.showUploadProgress = true;
                  scope.filename = file[0].name;
                  reader.readAsBinaryString(file[0]);
  
                  ctrl.$setValidity('validFile', elt.val() !== '');
                  scope.$apply(function() {
                      ctrl.$setViewValue(elt.val());
                      ctrl.$render();
                  });
              });
          }
      };
  });
  </code></pre>
  
  <p><strong>Inside controller:</strong></p>
  
  <pre><code>$scope.sendFile = function(reader, id) {
      var fd = new FormData();
      fd.append('id', id);
      fd.append('file', reader.result);
      fd.append('MAX_FILE_SIZE', 8 * 1024 * 1024);
      $http.post('api/upload.php', fd, {
          headers:            {'Content-Type' : undefined },
          transformRequest:   angular.identity
      }).then(function() {
          alert('upload success');
      }, function() {
          $scope.showUploadError = true;
          $scope.showUploadProgress = false;
          $scope.postError = 'Une erreur inconnue est survenue !';
      });
  };
  </code></pre>
  
  <p>On server side (file <code>api/upload.php</code>), I print variables <code>$_POST</code> and <code>$_FILES</code> with <code>print_r()</code>.</p>
  
  <p><strong>Why is <code>$_FILES</code> always empty, and my file data is in <code>$_POST['file']</code>?</strong></p>
  
  <p>I can create file from <code>$_POST['file']</code> data with php function <em><code>file_put_contents()</code></em> but I cannot make verifications that I can make with <em><code>$_FILES</code></em>. Is it really important (security issues)?</p>
  
  <p>If I change my POST <code>Content-Type</code> to <code>multipart/form-data</code>, the same thing happend.</p>