Php view and delete files

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

poshdosh


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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Manage</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
</head>
<body>
<?php

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";
    }

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