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

时间:2013-02-05 14:29:44

标签: php javascript html css file

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

1 个答案:

答案 0 :(得分:0)

你检查过PHP的delete function吗?

有一个如何使用它的简单示例:

<?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>