dimanche 27 décembre 2015

Checkbox always checked PHP/HTML

I'm trying to check what checkboxes are checked, and perform a file deletion depending on what checkboxes are checked. To me it seems like they ALWAYS have a value even if their not checked if I got the value".." in the checkbox. I currently removed the value in the checkbox, dident seem to make any diffrence.

Every checkbox is given a unique number, at the same time file its supposed to delete have the same index with its file name as data. But it NEVER sees that any of the checkboxes are even checked.. No errors, just not doing anything.. Please help

how it looks now picture

HTML and php:(document im working on is called protected.php)

<form action="protected.php" method="post"><br>

<input type="submit" name="Delete" value="Delete">

</form>


<?php

echo 'My files';
"<br>";
$mydr = "D:\wamp\www\\";
$dir = $mydr . $_SESSION['userid'];

// Open a directory, and read its contents
$checkbox_gen = 0;
$filename_gen = array();

if (is_dir($dir)){
  if ($dh = opendir($dir)){
    while ((($file = readdir($dh)) !== false)){

        if($file != '.' && $file != '..'){
        echo "<form><input type=\"checkbox\" name=\"$checkbox_gen\" id=\"checkbox\">" . "<a href=\"$dir/$file\">$file</a></form>" . "<br>";
        $filename_gen[$checkbox_gen] = $file;
        $checkbox_gen += 1;
        }
        }

    closedir($dh);
  }
}

?>

<br>
<form action="protected.php" method="post"><br>

<input type="submit" name="Delete" value="Delete">

</form>

<?php

if(isset($_POST['Delete'])) {

    for($i = 0; $i < 10; $i++){
        if(!empty($_POST[$i])) {
            echo $i . 'is checked';
            //$temp = $dir . '\\' . $filename_gen[$i];
            //unlink($temp);
            echo $temp;
        }

    }
}


?>




Aucun commentaire:

Enregistrer un commentaire