-
Notifications
You must be signed in to change notification settings - Fork 480
/
Copy pathlalala.php
217 lines (167 loc) · 6.16 KB
/
lalala.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<meta name="author" content="Orange Tsai">
<title> lalala | upload your photo </title>
<link rel="stylesheet" href="//bootswatch.com/cyborg/bootstrap.min.css">
<style type="text/css">
.hide-bullets {
list-style:none;
margin-left: -40px;
margin-top:20px;
}
.thumbnail {
padding: 0;
background: none;
border: none;
}
img {
max-width: 150px !important;
max-height: 150px !important;
}
small {
font-weight: 100 !important;
}
.carousel-inner>.item>img, .carousel-inner>.item>a>img {
width: 100%;
}
</style>
</head>
<body>
<?php
error_reporting(E_ALL^E_NOTICE);
function alert($msg){
die( '<script> alert("' . $msg . '");window.history.back(-1);</script>' );
}
function check_image($data){
if ( strlen($data) == 0 ){
alert( 'file error' );
}
if ( strstr($data, "\x00") == False and is_file($data) ){
$info = getimagesize($data);
} else {
$info = getimagesizefromstring($data);
}
$width = $info[0];
$height = $info[1];
$mime = $info['mime'];
if ( $width > 512 or $height > 512 ){
alert( 'image too large' );
}
// check type
$types = array( 'image/gif', 'image/jpg', 'image/jpeg' );
if ( !in_array( strtolower($mime) , $types) ){
alert( 'content error:' . htmlentities($data) ) ;
}
return 1;
}
$DIR = '/_www/uploads/';
$mode = $_POST['mode'];
if ( $mode == 'upload' ){
$file = $_FILES['file'];
$filename = $_SERVER['REMOTE_ADDR'] . '.jpg';
if( check_image($file['tmp_name']) )
move_uploaded_file($file['tmp_name'], $DIR . $filename);
} else if ( $mode == 'url' ){
$url = $_POST['url'];
$filename = $_SERVER['REMOTE_ADDR'] . '.jpg';
$allowed_ext = array('jpg', 'gif', 'png', 'jpeg');
if ( !in_array(pathinfo($url)['extension'], $allowed_ext) ){
alert( 'ext not allow' );
}
if ( substr($url, 0, 7) != 'http://' ){
alert( 'protocol error' );
}
if ( stristr($url, '.php') != False ){
alert( 'what do you do?' );
}
if ( stristr($url, 'file://') != False ){
alert( 'what do you do?' );
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_ALL);
$data = curl_exec($ch);
$http_info = curl_getinfo($ch);
if ( $http_info['http_code'] == 404 ){
alert('not found');
} else{
if ( check_image($data) )
file_put_contents($DIR . $filename, $data);
}
curl_close($ch);
}
$files = glob("uploads/*");
$files = array_combine($files, array_map("filemtime", $files));
arsort($files);
$files = array_keys($files);
$latest = array();
for ($i=0; $i<10; $i++){
$latest[$i] = $files[$i]? $files[$i]: 'unknown.jpg';
}
?>
<div class="container">
<div id="main_area">
<div class="row">
<div class="page-header center">
<h1> lalala <small> upload your photo </small> </h1>
</div>
</div>
<div class="row">
<div class="col-sm-3 col-md-offset-3">
upload from file
<form method="post" enctype="multipart/form-data">
<input type='hidden' name='mode' value='upload'>
<input type='file' name='file' >
<input type='submit' value='submit'>
</form>
</div>
<div class="col-sm-3">
upload from url
<form method="post" enctype="multipart/form-data">
<input type='hidden' name='mode' value='url'>
<input type='text' name='url'> <br>
<input type='submit' value='submit'>
</form>
</div>
</div>
<div class="row">
<div class="col-sm-12" id="slider-thumbs">
<ul class="hide-bullets">
<li class="col-sm-4">
<a class="thumbnail"><img src="<?php echo $latest[0];?>"></a>
</li>
<li class="col-sm-4">
<a class="thumbnail"><img src="<?php echo $latest[1];?>"></a>
</li>
<li class="col-sm-4">
<a class="thumbnail"><img src="<?php echo $latest[2];?>"></a>
</li>
<li class="col-sm-4">
<a class="thumbnail"><img src="<?php echo $latest[3];?>"></a>
</li>
<li class="col-sm-4">
<a class="thumbnail"><img src="<?php echo $latest[4];?>"></a>
</li>
<li class="col-sm-4">
<a class="thumbnail"><img src="<?php echo $latest[5];?>"></a>
</li>
<li class="col-sm-4">
<a class="thumbnail"><img src="<?php echo $latest[6];?>"></a>
</li>
<li class="col-sm-4">
<a class="thumbnail"><img src="<?php echo $latest[7];?>"></a>
</li>
<li class="col-sm-4">
<a class="thumbnail"><img src="<?php echo $latest[8];?>"></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</body>
</html>