mdversion1 Posted May 7, 2010 Share Posted May 7, 2010 I have this script that lists the files in a directory nicely with checkboxes to remove unwanted files but when I click the "Remove" button nothing happens. It won't delete anything. I think the problem lies in the array that unlinks the files. Any help is greatly appreciated. Here's the code: <?php // change this to your path (NO TRAILING [ / ]) $dir = "/path/to/dir/files"; ?> <form action="view_image_list.php" method="post"> <table border=0 cellpadding=2 cellspacing=0 width=380 align=center> <tr> <td width=40 align=center valign=middle bgcolor=336699 nowrap height=21> </td> <td width=240 valign=middle bgcolor=336699 nowrap> <font size=2 color=FFFFFF><B>File Name</B></font></td> <td width=80 align=center valign=middle bgcolor=336699 nowrap> <font size=2 color=FFFFFF><B>File Size</B></font></td></tr> <?php // Unlink Array if ((submit)&&($fid != "")) { foreach($fid as $rfn) { $remove = "$dir/$rfn"; unlink($remove); } } // List Files in Directory $handle=opendir($dir); while (($file = readdir($handle))!== false){ if ($file != "." && $file != "..") { $size = filesize("$dir/$file"); $list .= '<tr><td width="40" align="center" valign="middle" bgcolor="93BEE"2 nowrap height="21">'; $list .= '<input type="checkbox" name="fid[]" value="'.$file.'"></td>'; $list .= '<td width="240" valign="middle" bgcolor="93BEE2" nowrap>'; $list .= '<font size="2" color="336699">'.$file.'</font></td>'; $list .= '<td align="center" width="80" valign="middle" bgcolor="93BEE2" nowrap>'; $list .= '<font size="2" color="336699">'.$size.' Kb</font></td></tr>'; } } closedir($handle); echo $list; ?> <tr> <td colspan="3" align="center" valign="middle" bgcolor="336699" nowrap height="21"> <font size="2" color="FFFFFF"><input type="submit" value="Remove"></font></td></tr></table> </form> Quote Link to comment Share on other sites More sharing options...
mdversion1 Posted May 7, 2010 Author Share Posted May 7, 2010 Problem solved for anyone who likes : End results : <?php // change this to your path (NO TRAILING [ / ]) $dir = "/path/to/dir/files"; ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border=0 cellpadding=2 cellspacing=0 width=380 align=center> <tr> <td width=40 align=center valign=middle bgcolor=336699 nowrap height=21> </td> <td width=240 valign=middle bgcolor=336699 nowrap> <font size=2 color=FFFFFF><B>File Name</B></font></td> <td width=80 align=center valign=middle bgcolor=336699 nowrap> <font size=2 color=FFFFFF><B>File Size</B></font></td></tr> <?php $fid= $_POST['fid']; if (("submit")&&($fid != "")) { foreach($fid as $rfn) { $remove = "$dir/$rfn"; unlink($remove); } } $handle=opendir($dir); while (($file = readdir($handle))!== false){ if ($file != "." && $file != "..") { $size = filesize("$dir/$file"); $list .= '<tr><td width="40" align="center" valign="middle" bgcolor="93BEE2" nowrap height="21">'; $list .= '<input type="checkbox" name="fid[]" value="'.$file.'"></td>'; $list .= '<td width="240" valign="middle" bgcolor="93BEE2" nowrap>'; $list .= '<font size="2" color="336699">'.$file.'</font></td>'; $list .= '<td align="center" width="80" valign="middle" bgcolor="93BEE2" nowrap>'; $list .= '<font size="2" color="336699">'.$size.' Kb</font></td></tr>'; } } closedir($handle); echo $list; ?> <tr> <td colspan="3" align="center" valign="middle" bgcolor="336699" nowrap height="21"> <font size="2" color="FFFFFF"><input type="submit" value="Remove"></font></td></tr></table> </form> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.