Php 如何显示要删除的图像

Php 如何显示要删除的图像,php,Php,我有以下代码从文件夹中删除图像,但它不会在页面上显示图像,更糟糕的是,它会显示给定文件夹中的所有文件夹和文件 我只想删除图像,而不想删除任何具有给定文件夹名称的文件夹 我的代码是: <?php $path = "../imagefolder"; if(isset($_POST['file']) && is_array($_POST['file'])) { foreach($_POST['file'] as $file) { unlin

我有以下代码从文件夹中删除图像,但它不会在页面上显示图像,更糟糕的是,它会显示给定文件夹中的所有文件夹和文件

我只想删除图像,而不想删除任何具有给定文件夹名称的文件夹

我的代码是:

<?php
$path = "../imagefolder";

if(isset($_POST['file']) && is_array($_POST['file']))
{
    foreach($_POST['file'] as $file)
    {   
        unlink($path . "/" . $file) or die("Failed to <strong class='highlight'>delete</strong> file");
    }
    header("location: " . $_SERVER['REQUEST_URI']); //redirect after deleting files so the user can refresh without that resending post info message
}
?>
<form name="form1" method="post">
<?php

$path = "../imagefolder";
$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) 
{

if($file == "index.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;

echo "<input type='CHECKBOX' name='file[]' value='$file'>";
echo "<img src='$file' alt='$file'><br />";

}
closedir($dir_handle);

?>
<input type="submit" name="Delete" value="Delete">
</form>

改变这个

while (false !== ($file = readdir($dir_handle))) 


代码的这一部分:

$echo "<img src='$file' alt='$file'><br />";$
$echo“
”$
应该是:

$echo "<img src='$path$file' alt='$file'><br />";$
$echo“
”$
这应该可以解决它:)

$echo "<img src='$file' alt='$file'><br />";$
$echo "<img src='$path$file' alt='$file'><br />";$