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]" 
3
  • kindly use print_r($_POST['file']) in php file and see the output Commented Sep 11, 2018 at 3:36
  • same on my post php result. "[object File],[object File]". Commented Sep 11, 2018 at 3:39
  • try this posts may be you get an idea stackoverflow.com/a/31363033/9128487 Commented Sep 11, 2018 at 3:44

1 Answer 1

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]; } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.