I have a php file which lists all the files in a directory with checkboxes next to each one:
<html
<body>
<P>List of files:</p>
<form action="submitfiles.php" method="post">
<?php
if ($handle = opendir('./files')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$thelist .= '<a href="'.'./files/'.$file.'">'.$file.'</a>';
$thelist .= '<br>';
$s = '<input type="checkbox" name="'.$file.'" value="yes"/><a href="'.'./files/'.$file.'">'.$file.'</a>';
echo $s;
echo '<br';
}
}
closedir($handle);
}
?>
</body>
<input type="submit" name="formSubmit" value="Submit"/>
</form>
</html>
Then, I have a submitfiles.php, which loops through all the files, and gets the $_POST values for each checkbox.
<?php
if ($handle = opendir('./files')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
echo 'Value is ' . $_POST['$file'] . '<br>';
echo $file . '<br>';
}
}
closedir($handle);
}
?>
Even if I check a checkbox though, the line "Value is " in my php file always prints a blank. Meaning, none of the checkboxes are ever given a value. How do I get this working? If I checked a checkbox, I want it to print "Value is yes", but it doesn't.