Codice PHP:
<?php
$cartella = "./";
$i = 0;
if ( isset( $_GET['file']) )
{
$filetodelete = $_GET['file'];
}
foreach ( scandir($cartella) as $f )
{
$i++;
if ($f == "." || $f == ".." || $f == basename(__FILE__) ) continue;
$chk = md5("file_" . $f);
$fileentry = "<div id = \"file_$i\"><input type = \"button\" value = 'X' onClick = \"deletefile('$chk','file_$i')\"> $f</div>";
echo $fileentry;
if ( isset($filetodelete) && $chk == $filetodelete)
{
unlink($f);
}
}
?>
<script>
function deletefile(who, elem)
{
http = new XMLHttpRequest();
http.onreadystatechange = function() {
if (http.readyState == 4 && http.status == 200) {
document.getElementById(elem).style.display = 'none';
}
}
http.open("GET", "?file=" + who, true);
http.send();
}
</script>