PHP, Verzeichnis mit inhalt löschen
rm.class.php

<?php
header('Content-Type: text/html; charset=ISO-8859-1');
foreach($_POST as $x => $y){
   $$x = trim($y);
}
if(isset($oname)){
 echo "<script type='text/javascript'>var bestaetigung = window.confirm('Ordner ".$oname." löschen?\\nAlle Daten werden mit gelöscht!');
    if(bestaetigung){location.href='rm.php?del=ja&oname=$oname'}else{location.href='rm.php'}</script>";
 exit;
}
?>
<html>
<head>
<title>Unterordner löschen</title>
</head>
<body>
<?php
foreach($_GET as $x => $y){
 $$x = trim($y);
}
if(isset($del) && $del == "ja"){
 require_once 'rm.class.php';
 $deldir = new RMDO(); $deldir->delDir($oname);
 unset($del);
 header("Location: rm.php?text=Ordner ".$oname." erfolgreich gelöscht!!!");
}
if(isset($text)){echo $text;}
?>
<form name='rmo' method="POST" action="rm.php">
<?php
echo "<h4 style='color:#808080;margin-left:10px;'>Unterordner:</h4>";
echo "<hr style='border:1px solid #C0C0C0;'><br>";

$handle=opendir("./");
$i = '';
while ($datei = readdir ($handle))
{
 if (is_dir($datei) && $datei != "." && $datei != ".." && $datei)
 {
   $i++;
   if ($i ==3){echo "<br><br>"; $i=1;}
   echo '<input type="submit" name="oname" value="'.$datei.'" style="width:250px; height:25px;margin-left:10px;"/>';
 }
}
closedir($handle);
?>
</form>
</body>
</html>
       

Kopieren

rm.php

<?php
error_reporting(E_ALL);
class RMDO {
public $eintrag;
public $file;
public $pfad;
    public function delDir($dir)
    {
        $eintrag = opendir($dir);
        while($file = readdir($eintrag))
        {
            $pfad = $dir . '/' . $file;

            if ($file != "." && $file != "..")
            {
                if (is_dir($pfad))
                    $this->deldir($pfad);
                else
                    unlink($pfad);
            }
        }
        closedir($eintrag);
        rmdir($dir);
    }
}
?>
       

Kopieren