-3

I am trying to find a solution to remove files from a directory listing. I found an example that works bery well for files within the same directory. However I assume that I would need to change directories but I am not understanding how to accomplish this.

Here is the example that works for files in the current directory

<?php 
    if(isset($_GET['delete'])){
        $delurl=$_GET['delete'];
        unlink($delurl);
    }
?>

<?php

if ($handle = opendir('.')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
            echo "<br><b><a href=\"$entry\">$entry</a> -         <a href=\"?delete=$entry\">Delete</a><br></b>";
        }
    }
    closedir($handle);
}
?>
  • Kinda hard to understand what your asking. – Charlie Fish Aug 06 '16 at 20:52
  • I would like to change directory to '../videos/' rather than '.' But I dont know how that is done. If i use that location the file cannot be deleted because php is looking for the file in '.' – mattkingusa Aug 06 '16 at 20:55

1 Answers1

1

Ok got it.

<?php 
    if(isset($_GET['delete'])){
        $delurl=$_GET['delete'];
        unlink($delurl);
    }
?>

<?php


if ($handle = opendir('../videos/')) {
while (false !== ($entry = readdir($handle))) {
    if ($entry != "." && $entry != "..") {
        echo "<br><b><a href=\"$entry\">$entry</a> - <a     href=\"?delete=../videos/$entry\">Delete</a><br></b>";
    }
}
closedir($handle);
}
?>

I just added the path after href=\?delete= and before $entry