I think my question is clear enough but here some details. I pretty new to Angular and PHP so I probably did a lot of mistakes or missing something important :).
I have first of all a form containing text and file inputs. Like this :
<div><label for="textInput">Text input</label></div>
<div><input id="textInput" name="textInput" type="text" ng-model="form.textInput"></div><br/>
<div>Put some file please</div>
<div>
<input id="file1" type="file" name="file1" ng-model="form.file1"><br/>
<input id="file2" type="file" name="file2" ng-model="form.file2">
</div>
To post file with ng-model I used this directive :
(function () {
fileInput.$inject = [];
function fileInput() {
var fileTypeRegex = /^file$/i;
return {
restrict: 'E',
require: '?ngModel',
link: link
};
function link(scope, element, attrs, ngModel) {
if (ngModel && element[0].tagName === 'INPUT' && fileTypeRegex.test(attrs['type'])) {
element.on('change', function () {
var input = this;
if ('multiple' in attrs) {
var files = Array.prototype.map.call(input.files, function (file) { return file; });
ngModel.$setViewValue(files);
}
else {
ngModel.$setViewValue(input.files[0]);
}
});
}
}
}
angular.module('ng-file-input', []).directive('input', fileInput);
}());
Finally, I send data with $http :
$http({
url: window.API_URL + 'postulate.php',
method:'POST',
data:$scope.form
}).then(function successCallback(response){
console.log(response.data);
console.log($scope.form);
});
In PHP file I only get $_POST data and I print it :
$rest_json = file_get_contents("php://input");
$_POST = json_decode($rest_json, true);
echo json_encode($_POST);
And here's the problem. I get with console.log() :
Object {textInput: "the content", file1: Array[0], file2: Array[0]}
Object {textInput: "the content", file1: File, file2: File}
Did a lot of Google and tests but I can't get it to work.
Ask me if you want more details.