1

I'm using drop zone and angularjs. I want to upload multiple images and send it to the server. I'm trying to process my upload on custom rather than to process on the drop zone. I'm storing all accepted files on drop zone to ng-model so that I will grab all images and upload to the server. my problem is how to loop array images on php. Any idea how to achieve this?

js

 $scope.saveform = function(){
  var fd=new FormData();
  console.log($scope.info.allimages);

  fd.append('type','form');
  fd.append('file',$scope.info.allimages);

    $http.post(httprequest, fd,{
          transformRequest: angular.identity,
          headers: {'Content-Type': undefined, 'Process-Data': false}
      }
  ).then(function(response) {


  });
}

js console.log result:

[File {upload=Object, status="queued", ...}, File {upload=Object, status="queued", ...}]

dropzone config:

  $scope.dropzoneConfig2 = {
    'options': {
        url : httprequest,
        acceptedFiles : 'image/jpeg, images/jpg, image/png',
        addRemoveLinks : true,
        parallelUploads : 20,
        maxFiles: 20,
        uploadMultiple: true,
        autoProcessQueue : false,
        init: function () {
              var vm = this;
        }
    },
    'eventHandlers': {
          'addedfile': function(file) {
              $scope.info.allimages = this.getAcceptedFiles();
          },
          'removedfile': function(file) {
          },
          'sending': function (file, xhr, formData) {
          },
          'success': function (file, response) {
          }
     }

  }

php:

if($_POST['type']=='form'){
echo json_encode($_POST['file']));}

php result:

"[object File],[object File]"
Noor A Shuvo
  • 2,639
  • 3
  • 23
  • 48
Rye
  • 179
  • 3
  • 17

1 Answers1

1

Try like this.

for($count = 0; $count<count($_FILES["files"]["name"]); $count++)
{
    $_FILES["file"]["name"] = $_FILES["files"]["name"][$count];
    $_FILES["file"]["type"] = $_FILES["files"]["type"][$count];
    $_FILES["file"]["tmp_name"] = $_FILES["files"]["tmp_name"][$count];
    $_FILES["file"]["error"] = $_FILES["files"]["error"][$count];
    $_FILES["file"]["size"] = $_FILES["files"]["size"][$count];
}
Vijay Makwana
  • 911
  • 10
  • 24