2017-10-03 3 views
0

私は次のことをしています。上記の画像をクリックして上記のチェックボックスをオンにする機能を追加したいと思います。 29〜32行目と思われる。私は例を見つけたが、私のために働かなかった。javascriptのチェックボックス(画像のチェックボックスをクリック)help w/php

おかげ

<html> 
 
<head> 
 
    <title>This is a simple PHP script to delete select images.</title> 
 
</head> 
 
<body> 
 
    <?php 
 
     if (isset($_POST['image_list'])) { 
 
      foreach ($_POST['image_list'] as $imagename) { 
 
       if (file_exists($imagename)) { 
 
        unlink($imagename);  
 
       } 
 
      } 
 
     } 
 
    ?> 
 
    <form action="images_view.php" method="POST"> 
 
     <p>Please select multiple images you want to remove. Please note that the selected images will be removed from server as well.</p> 
 
     <?php 
 
      $files = glob("videos/THUMBNAILS/*.*"); 
 
      for ($i=0; $i<count($files); $i++) 
 
      { 
 
       $image = $files[$i]; 
 
       $supported_file = array(
 
        'jpg', 
 
       ); 
 

 

 
       $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION)); 
 
       if (in_array($ext, $supported_file)) { 
 
        echo '<input type="checkbox" name="image_list[]" style="margin-right:10px;" value="'.$image.'" />'; 
 
        echo '<input type="checkbox" name="image_list[]" style="margin-right:10px;" value="'.$image.'" />'; 
 
        echo basename($image)."<br />"; // show only image name if you want to show full path then use this code // echo $image."<br />"; 
 
        echo '<img src="'.$image .'" style="max-width: calc(100% - 20px); alt="Random image" />'."<br /><br />"; 
 
       } else { 
 
        continue; 
 
       } 
 
      } 
 
     ?> 
 
     <input type="submit" name="submit" style="width:300px;height:60px;margin-left:20px;" value="Delete" /> 
 
    </form> 
 
</body> 
 
</html>

答えて

0
あなただけのラベルで、チェックボックスの入力や画像をラップすることができます

:あなたは、単に行うことができますバックエンドで

<label> 
    <input type="checkbox" name="image_list[<?php echo $imageId; ?>]" /> 
    <img src="https://lh3.googleusercontent.com/ez8pDFoxU2ZqDmyfeIjIba6dWisd8MY_6choHhZNpO0WwLhICu0v0s5eV2WHOhuhKw=w170" /> 
</label> 

Demo

foreachとdelete

foreach (array_keys($_POST['image_list']) as $imageId) { 
    // delete image by id. 
} 
+0

次のコードは、チェックボックスが選択されている画像をクリックすると機能しますが、「削除」機能は動作していません。 –