Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP File Delete Issue?
    primarykey
    data
    text
    <p>I have the following HTML form:</p> <pre><code>&lt;form action='delete.php' method='POST'&gt; &lt;table&gt; &lt;div class = '.table'&gt; &lt;?php $dir = '../uploads/store/'; $newdir = ereg_replace('\.','',$dir); if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (!preg_match('/^(\.(htaccess|\.)?|index\.html)/',$file)) { echo "&lt;tr&gt;&lt;td&gt;&lt;font color = 'white'&gt;&lt;a href='$newdir$file'&gt;$file&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;"; echo "&lt;td&gt;&lt;input type='submit' value ='Delete'&gt;&lt;/td&gt;&lt;/tr&gt;"; echo "&lt;input align='right' type='hidden' value='$file' name='file'&gt;"; } } closedir($dh); } } ?&gt; &lt;/div&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p>Which links to the following PHP script:</p> <pre><code>&lt;?php session_start(); $file = $_POST['file']; $dir = '../uploads/store/'; $file = $dir . $file; opendir($dir); if(unlink($file)) { echo "File sucessfully deleted"; $_SESSION['username'] = 'guitarman0831'; header('Refresh: 2;url=http://www.ohjustthatguy.com/uploads/uploads.html'); } else { echo "Error: File could not be deleted"; $_SESSION['username'] = 'guitarman0831'; header('Refresh: 2;url=http://www.ohjustthatguy.com/uploads/uploads.html'); } ?&gt; </code></pre> <p>However, when the Delete button is pressed in the HTML form, the item above the one intended to delete is deleted.</p> <p>Hope this makes sense.</p> <p>NOTE: I'm not going for security with these scripts, I'm going to work on that later. It's only me using this service right now.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload