-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
83 lines (66 loc) · 1.51 KB
/
index.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
<?php
include('lib.php');
html_header();
echo <<<EOF
<form action="upload" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Image</td>
<td><input type="file" name="images[]" multiple="multiple"/></td>
</tr>
EOF;
if ($HASHED_PASSWORD) {
echo <<<EOF
<tr>
<td>Password</td>
<td><input type="password" name="password" /></td>
</tr>
EOF;
}
echo <<<EOF
<tr>
<td></td>
<td><input type="submit" value="Upload" /></td>
</tr>
</table>
</form>
<h2>Recent Uploads</h2>
EOF;
# https://stackoverflow.com/questions/11923235/scandir-to-sort-by-date-modified
function scan_dir($dir) {
$ignored = array('.', '..');
$files = array();
foreach (scandir($dir) as $file) {
// TODO: match extensions instead
if (in_array($file, $ignored)) {
continue;
}
$files[$file] = filemtime($dir . '/' . $file);
}
arsort($files);
$files = array_keys($files);
return $files;
}
$i = 0;
foreach (scan_dir($UPLOAD_DIR) as $file) {
// sanitized on the file system
$url = "resize?name=$file&max-width=400";
$orig_url = "$UPLOAD_DIR/$file";
$kilobytes = number_format(round(filesize($orig_url) / 1000));
echo <<<EOF
<p>
<code> <a href="$url">$file</a> </code>
( <a href="$orig_url">original</a> is $kilobytes KB,
<a href="form?filename=$file">form</a>)
<br/>
<img src="$url">
</p>
EOF;
$i++;
if ($i === 30) {
break;
}
}
# And then <img src="resize?name=$name&max-width=100"> for small thumbnails
html_footer();
?>