title: Delete dir and data from mysql
body: <p>I use form which one upload file into folder and info(name, size) into database.So i want to make deleting form which one delete file and data from database. </p>
  
  <pre><code>&lt;?php
  include '../dbc.php'; 
  $tbl_name="image"; // Table name
  
  $sql="SELECT * FROM $tbl_name";
  $result=mysql_query($sql);
  
  //detect file
  $directory  = "../../Upload/"; 
  $images = scandir($directory);
  $ignore = Array(".", "..");
  ?&gt;
  
   &lt;table width="800px" style="background:white;margin:50px auto; font-size:13px;" border="1" cellpadding="3"&gt;
            &lt;tr&gt;
            &lt;td colspan="3"&gt;&lt;strong&gt;Delete:&lt;/strong&gt; &lt;/td&gt;
            &lt;/tr&gt;
  
            &lt;tr&gt;
            &lt;td width="40%" align="center"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;
            &lt;td width="10%" align="center"&gt;&lt;strong&gt;Size&lt;/strong&gt;&lt;/td&gt;
            &lt;td width="5%" align="center"&gt;&lt;strong&gt;Delete&lt;/strong&gt;&lt;/td&gt;
            &lt;/tr&gt;
  
            &lt;?php
            while($rows=mysql_fetch_array($result)){
            ?&gt;
            &lt;tr id='del'&gt;
            &lt;td&gt;&lt;?php echo $rows['name']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo number_format($rows['imgSize'], 2) ?&gt; MB&lt;/td&gt;
            &lt;td&gt;&lt;a name="delete" href="delData1.php?id=&lt;?php echo $rows['imgId']; 
             ?&gt;"&gt;Delete&lt;/a&gt;&lt;/td&gt;
            &lt;/tr&gt;
  
            &lt;?php
            }
            ?&gt;
  
            &lt;/table&gt;
            &lt;?php
            mysql_close();
            ?&gt;
  </code></pre>
  
  <p>delData1.php</p>
  
  <pre><code>&lt;?php
  include '../dbc.php';
  $tbl_name="image"; // Table name
  // get value of id that sent from address bar
  $id=$_GET['id'];
  
  $filename = $_POST['filename'];
  $path = $_POST['directory'];
  if(file_exists($path."/".$filename)) { 
   unlink($path."/".$filename); //delete file
  }
  
  // Delete data in mysql from row that has this id
  $sql="DELETE FROM $tbl_name WHERE imgId='$id'";
  $result=mysql_query($sql);
  
  // if successfully deleted
  if($result){
      rmdir('$name');
  echo "Deleted";
  echo "&lt;BR&gt;";
  header("Location:Data.php");
  }
  
  else {
  echo "ERROR";
  }
  ?&gt;
  </code></pre>
  
  <p>It's delete data from database, but file stay in folder.</p>