I am trying to upload image into the folder with angularjsand php.
Here is html part:
<button ng-click="addNewEvent()">Add Event</button>
<form ng-submit="addRoadmapEvent(events)">
<span ng-repeat="event in events">
<input type="text" ng-model="event.month" required=""/>
<input type="file" ng-model="event.img" file-input="files" />
</span>
<input type="submit" value="Submit">
</form>
Function addNewEvent() allows to add another row with month and image so I will have something like this:
Then after pressing submit button I want to move selected images into my folder, I am using directive for it and then addRoadmapEvent function:
$scope.addRoadmapEvent = function (events){
var imgs = [];
var form_data = new FormData();
//set the data array
angular.forEach(events, function(event){
imgs.push(event.img);
});
var i = 0;
angular.forEach(imgs, function(file){
console.log(i++);
form_data.append('file', file[0]);
$http.post('House/house_action.php/roadmap_img', form_data, {transformRequest: angular.identity,headers: {'Content-Type': undefined,'Process-Data': false}}).then(function(response){
console.log(response.data);
});
});
};
It works perfectly the only problem is $http.post. Its posting same photo twice:
How can i make it send one by one?

