在动态情况下为相应的图像分配按钮


assigning buttons to corresponding images in dynamic situation

我有一个包含1000个或更多文件的文件夹。我可以在浏览器上显示文件的缩略图(使用opendir、readdir和is_dir)。我还为每个图像分配了一个按钮。我现在需要的是,例如,点击第500个按钮后,第500个图像被删除。因此,源文件夹中不再有该图像可用。如有任何帮助,我们将不胜感激。

你检查过PHP的删除功能吗?

有一个简单的例子说明如何使用它:

<?php
while(!$file = readdir($pathToImagesFolder)){
  if(file_exists($pathToImagesFolder.$file)){
    delete($pathToImagesFolder.$file);
  }
}
?>

您的按钮应该调用一个操作(或文件,在本例中为deleteImage.php),该操作只为所需的图像执行代码。(通常通过按钮值属性作为参数传递给函数)

<form action="deleteImage.php" id="doNotMatchForm" method="post">
    <input name="submit" class="button" type="submit" value="nameOfImage500th.jpg">
</form>