-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange.html
107 lines (87 loc) · 3.44 KB
/
change.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Welcome to ESN</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/cover.css" rel="stylesheet">
<!-- Angularjs Core Files -->
<script type="text/javascript" src="angular.js"></script>
<!--Starting Angularjs App -->
<script>
angular.module('esn', [])
.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 () {
modelSetter(scope, element[0].files);
});
});
}
};
}]).service('fileUpload', ['$http', function ($http) {
var files = [];
return {
uploadFileToUrl: function (file, uploadUrl) {
var fd = new FormData();
fd.append('profile_photo', file);
console.log(fd);
$http.post(uploadUrl, fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function (data) {
console.log(data);
files.push(data.files);
})
.error(function (error) {
console.log(error);
});
},
getFiles: function () {
return files;
}
}
}]).controller('fileCtrl', function ($scope, fileUpload) {
$scope.uploadfile = function () {
var file = $scope.myFile;
var uploadUrl = 'http://esnback.com/users/addProfilePhoto.json';
for (var i = 0; i < file.length; i++) {
fileUpload.uploadFileToUrl(file[i], uploadUrl);
}
};
$scope.images = function () {
return fileUpload.getFiles();
}
});
</script>
</head>
<style>
.myimage {
position: relative;
width: 200px;
margin: 20px;
padding: 20px;
border-radius: 5px;
float: left;
}
</style>
<body ng-app="esn">
<div ng-controller="fileCtrl">
<input type="file" file-model="myFile" multiple/>
<button ng-click="uploadfile()">Upload me</button>
<a ng-repeat="image in images()" class="myimage" ng-href="{{image}}">
<img ng-src="{{image}}" class="myimage"/>
</a>
</div>
</body>
</html>