title: How to add delete in php script in my photo gallery
body: <p>I made a Photo gallery by php.<br>
  I am able to make upload image and show the image list. But i want to add a delete button where users can delete there unwanted image. But i was failed to add this button work. </p>
  
  <p>Someone please help to fix it?</p>
  
  <p>Here is my code on GitHub: <a href="https://github.com/sagar290/photo_gallerey/blob/6cad3743e735ea109723de7e14d5477bff1e964b/gallery.php" rel="nofollow">https://github.com/sagar290/photo_gallerey/blob/6cad3743e735ea109723de7e14d5477bff1e964b/gallery.php</a></p>
  
  <pre><code>&lt;?php
  
  if (isset($_FILES["file"]["name"])) {
    $name = $_FILES['file']['name'];
    //$size = $_FILES['file']['size'];
    //$extention = $type;
    $type = strtolower($_FILES['file']['type']);
    $tmp_name = $_FILES['file']['tmp_name'];
  
  
    if (isset($name)) {
      if (!empty($name)) {
        if (($type=='image/jpg')||($type=='image/jpeg')||($type=='image/gif')) {
          $location = 'photos/';
  
          if(move_uploaded_file($tmp_name, 'photos/'.$name)) {
            echo $name.' is uploaded';
  
          }
        }else {
          echo 'file must be jpg or jpeg ';
        }
  
  
      }else {
        echo 'please choose a file';
      }
    }
  }
  
   ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;Photo gallery&lt;/title&gt;
  
      &lt;style type="text/css"&gt;
          ul {
            list-style-type: none;
          }
        li {
          float: left;
          padding: 10px;
          margin: 10px;
          font: bold 10px Verdana, sans-serif;
        }
        img {
          display: block;
          border: 1px solid #333300;
          margin-bottom: 5px;
        }
      &lt;/style&gt;
  
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h2&gt;Photo gallery&lt;/h2&gt;
  
        &lt;form action="gallery.php" method="POST" enctype="multipart/form-data"&gt;
        UPLOAD:
        &lt;input type="file" name="file"&gt;&lt;br&gt;&lt;br&gt;
        &lt;input type="submit" value="submit"&gt;
      &lt;/form&gt;
  
        &lt;ul&gt;
          &lt;form action="gallery.php" method="POST"&gt;
  &lt;?php
  
  
      //define location of photo image
      $photosDir = './photos';
  
      //define which file extention are images
      $photosExt = array('gif','jpg','jpeg','tif','tiff','bmp','png');
  
      //initialize array to hold filenames of images found
      $photoList = array();
  
      //read directory contents
      //build photo list
      if (file_exists($photosDir)) {
        $dp = opendir($photosDir) or die('Error: cannot open file');
        while ($file =  readdir($dp)) {
          if ($file != '.' &amp;&amp; $file != '..') {
            $fileData = pathinfo($file);
            if (in_array($fileData['extension'], $photosExt)) {
              $photoList[] = "$photosDir/$file"; // file includes as an array
            }
          }
        }
        closedir($dp);
      }else {
        die('ERROR: directory dosent exists');
      }
  
      //itarate over photo list
      //display each image and file name
      if (count($photoList)&gt;0) {
        for ($x=0; $x &lt;count($photoList) ; $x++) {
          ?&gt;
  
          &lt;li&gt;
            &lt;input type="submit" name="delete" value="Delete"&gt;
            &lt;img src="&lt;?php echo $photoList[$x]; ?&gt;" height="150" width="200"/&gt;
            &lt;?php echo basename($photoList[$x]); ?&gt;&lt;br&gt;
            &lt;?php echo round(filesize($photoList[$x])/1024) . 'KB'; ?&gt;
          &lt;/li&gt;
  
          &lt;?php
        }
      } else {
        die('ERROR: No image found');
      }
  
  
  
  
  
  ?&gt;
  
      &lt;/form&gt;
    &lt;/ul&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>