2017-10-03 1 views
0

나는 아래의 이미지를 클릭하여 위의 체크 박스를 클릭 할 수있는 기능을 추가하고 싶습니다. 가능합니까? 29-32 줄로 보입니다. 예를 발견했지만 저를 위해 일하지 않았습니다.자바 스크립트 체크 박스 (클릭 이미지 - 체크 박스)

감사

<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

체크 표시가 선택된 이미지를 클릭하면 다음 코드가 작동하지만 "삭제"기능이 작동하지 않습니다. –