I am trying to remove checked files from a directory.
From the code below, you see I open a directory called upload, and print to the web page all the files in that directory. Each file has a check box next to it's name. I want the users of this page to be able to check the check box and click the delete button to delete files from the upload directory.
Using an onClick event handler, I'm trying to use php embeded in javascript to delete the checked files. When I click the delete button, nothing happens. I'm sure I'm probably going about this all wrong.
Any ideas???
<SCRIPT language="JavaScript">
function delete_checked_files()
{
if (form1.checkbox.value=="yes") {
<?
exec("rm file.$file");
?>;
return (false);
}
}
</SCRIPT>
<form name="form1">
<?
$dh = opendir('upload');
while($file = readdir($dh)) {
//if $file == '.' or == '..' skip it
//and if file extension == '.php3' or '.php' or '.phtml' make a link to $file
if($file != '.' && $file != '..' && ereg(".(php3|php|phtml|doc|wk4|xls)",$file)) {
echo "<INPUT TYPE=checkbox NAME=checkbox value=$checked> <A href=/construction/upload/$file>$file</A>\n";
print "<br>";
}
}
?>
</form>
<p>
<input type="submit" name="Delete" value="Delete" onClick="delete_checked_files()">
</p>