Forum Moderators: coopster
The script works fine, but it also reads and displays the directories within the images directory, so it displays them as broken images with a checkbox by them. How do I exclude the directories from being listed?
$file_ary = isset($_POST['rfile']) ? $_POST['rfile'] : array();
if ($file_ary){header("Refresh: 2;");}
$image_path = dirname(__FILE__) . '/images';
$dir_handle = null;
if (!($dir_handle = opendir($image_path)))
{
//trigger_error('error, path not found');
return;
}
$html = '<html><form method="post">';
$file = readdir($dir_handle);
while ($file)
{
$html .= "<img src='images/{$file}' height='10%' width='10%'><input type=\"checkbox\" name=\"rfile[]\" value=\"{$file}\" />\r\n";
$file = readdir($dir_handle);
}
closedir($dir_handle);
$html .= '<br><br><input type="submit" name="submit" value="DELETE" />';
$html .= "</form></html>";
echo $html;
if (!empty($file_ary))
{
$dir = 'images/';
foreach ($file_ary as $key => $value) {
if (unlink($dir.$file_ary[$key])){}
}
echo "<br><DIV ALIGN='CENTER'><img src='load.gif'></DIV><br>";
}