Prova così allora:
Codice PHP:
<?php
$id = $this->row->id;
$dir = "mydir";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
echo <<<EOT
<form action="" method="POST" onSubmit="confirm('Sicuro di voler cancellare questo file?');"><select name="file">
EOT;
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$ext = substr($file, strrpos($file, '.') + 1);
if ($ext == 'pdf'){
echo '<option value="'.$file.'">'.$file.'</option>';
}
}
closedir($dh);
}
echo '</select>
<input type="submit" value="Cancella" name="canc" /></form>
';
}
if(isset($_POST['canc'])) {
$file_selezionato = $_POST['file'];
if(unlink("/".$dir."/".$file)) {
echo 'File cancellato correttamente.';
} else {
echo 'Errore: riprovare.';
}
}
?>
Se non va così:
Codice PHP:
<?php
$id = $this->row->id;
$dir = "mydir";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
echo <<<EOT
<form action="" method="POST" onSubmit="confirm('Sicuro di voler cancellare questo file?');"><select name="file">
EOT;
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$ext = substr($file, strrpos($file, '.') + 1);
if ($ext == 'pdf'){
echo '<option value="'.$file.'">'.$file.'</option>';
}
}
closedir($dh);
}
echo '</select>
<input type="submit" value="Cancella" name="canc" /></form>
';
}
if(isset($_POST['canc'])) {
$file_selezionato = $_POST['file'];
if(unlink("./".$dir."/".$file)) {
echo 'File cancellato correttamente.';
} else {
echo 'Errore: riprovare.';
}
}
?>