php - images upload with angularjs -
i got @ small problem images upload in angular.
this code working fine send php out eny trobels, can se the post request there array of data, problem when try print_r($_files); php theres , empty array.
socialctrl.directive('upload', function() { return { restrict: 'a', replace: true, controller: function($scope, $http, $rootscope) { var formdata = (window.formdata) ? new formdata() : false; $(".upload").bind("change", function (evt) { var file = this.files[0]; if (!!file.type.match(/image.*/)) { if ( window.filereader ) { var reader = new filereader(); reader.onloadend = function (e) { $(".preview").find("img").attr("src", e.target.result); }; reader.readasdataurl(file); } if (formdata) formdata.append("file", file); } if (formdata) { $http({ method: 'post', url: 'php/imagesuploader.php', data: formdata, cache:false, contenttype: false, processdata: false, }).success(function(result) { console.log(result) }); } }); } } })
you can't post file this, have either submit form data (as multipart form data) or transform request (as shown in this blogpost).
simple example of how post form data shown below.
var fd = new formdata(); fd.append('file', file); $http.post(uploadurl, fd, { transformrequest: angular.identity, headers: {'content-type': undefined} }) .success(function(){ }) .error(function(){ });
Comments
Post a Comment