javascript — угловая загрузка файла в бэкэнд PHP

Я разработчик, и я пытаюсь изучить некоторые из AngularJ, теперь я пытаюсь сделать форму, и необходимо отправить файл из input [file] в php, но когда я нажимаю на кнопку, файл не отправляется этому php, Попробуйте с некоторыми примерами, но ни один не работал.

С уважением!!

мой код:

<form>
<input type="file" file-model="csvFile" name="contactFile" on-read-file="showContent($fileContent)" class="filestyle glyfecha glyphicon input-sm" />
<button type="submit" class="btn btn-success btn-block" ng-click="sendForm()" style="margin-top: 10px;margin-bottom: 10px;">Guardar contactos</button>
</form>app.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;

element.bind('change', function(){
scope.$apply(function(){
console.log(element[0].files[0]);     //this work
modelSetter(scope, element[0].files[0]);
});
});
}
};
}]);

app.service('fileUpload', ['$http', function ($http) {
this.uploadFileToUrl = function(file){
var fd = new FormData();
fd.append('file', file);
$http.post('v1/contact/upload/0', fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.then(function(response){
console.log(response.data);
})
}
}]);

app.controller('addcontacto', ['$scope', 'fileUpload', function($scope, fileUpload){
$scope.sendForm = function() {
var file = $scope.csvFile;
fileUpload.uploadFileToUrl(file);
};
}]);

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector