Php view and delete files

Started by poshdosh, May 22, 2012, 01:06:07 AM


Hi all

I've been writing a script to view all the files in a dir
It also has a form which you need to be able to then delete one of the files.
Here is my code so far:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>

if ($handle = opendir('img/')) {
    echo "Files:\n";

    /* This is the correct way to loop over the directory. */
    while (false !== ($entry = readdir($handle))) {
        echo "$entry\n";

<form action="<?=$_SERVER['PHP_SELF'];?>" method="post"
Filename: <input type="text" name="file"
<br />
<input type="submit" name="Submit" value="Submit" />
$DelFilePath = $setup["$file"] . $fileName;
# delete file if exists
if (file_exists($DelFilePath)) { unlink ($DelFilePath); }