This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
show.php
56 lines (52 loc) · 1.78 KB
/
show.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
<?php
// Niente accessi diretti
if(!isset($hash_pwd)) die('Accesso diretto non consentito!');
if(isset($_GET['id'])){
// Procedura di cancellazione
$path = realpath('./download/'.$_GET['id']);
if(is_readable($path)) {
unlink($path);
echo <<<_END
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Fatto!</strong> Il file è stato cancellato correttamente.
</div>
_END;
} else {
// File non cancellabile
echo <<<_END
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Attenzione!</strong> Non ho i permessi per cancellare il file.
</div>
_END;
}
}
echo <<<_END
<h4 class=\"muted\">File disponibili</h4>
<table class="table table-hover">
_END;
$n_file = 0;
if($handle = opendir('./download')) {
while(false !== ($entry = readdir($handle))) {
if($entry != "." && $entry != "..") {
$n_file++;
printf("\n<tr><td>%s</td><td></td>", $entry);
printf("<td>%s</td>", human_filesize(filesize('./download/'.$entry)));
printf("<td><a class=\"btn btn-primary\" href=\"download/%s\">Scarica</a></td>", $entry);
printf("<td><a class=\"btn btn-danger\" href=\"index.php?mode=2&id=%s\">Cancella</a></td>", $entry);
echo "</tr>";
}
}
if($n_file == 0) {
echo "<tr><td>Nessun file</td></tr>";
}
printf("\n</table>");
closedir($handle);
}
function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
?>