Javascript Angular js文件上载问题
以下是我的控制器代码和上载文件的自定义指令:Javascript Angular js文件上载问题,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,以下是我的控制器代码和上载文件的自定义指令: angular.module('myApp', []) .directive('fileModel', ['$parse', function ($parse) { return { restrict: 'A', link: function(scope, elemesnt, attrs) { element.bind('change', function(){
angular.module('myApp', [])
.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, elemesnt, attrs) {
element.bind('change', function(){
$parse(attrs.fileModel).assign(scope,element[0].files)
scope.$apply();
});
}
};
}])
.controller('myCtrl', ['$scope', '$http', function($scope, $http){
$scope.uploadFile=function(){
var fd=new FormData();
console.log($scope.files);
angular.forEach($scope.files,function(file){
fd.append('file',file);
});
$http.post('http://192.168.1.161/www/ci_practice/assets/',fd,
{
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
}).success(function(d)
{
console.log(d);
})
}
}]);
我无法将图像上载到资产文件夹。
请帮助我。您可能不想让所有人都能看到您使用的IP地址。如果您仔细阅读并以更好的方式反映问题,这将非常有帮助。你可以参考。祝你好运我们可以将上传的文件保存到文件夹中吗..我是angular js的新手,你能帮我编写代码吗?你的意思是你想将文件上传到你的文件夹中吗?然后你需要在后端执行-我的意思是最佳实践。什么是uur后端我使用php mysql
var f = $scope.files,
r = new FileReader();
r.onloadend = function(e) {
var data = e.target.result;
//send your binary data via $http
}
r.readAsBinaryString(f);