Listing and Deleting Files in a directory
Posted: Thu Oct 25, 2007 8:20 am
I succeeded in creating a simple posting system. Data is stored in seperate text files in a directory called "posts".
Now the listing and deleting system works as well BUT I HAVE to put the list.php and the delete.php in the posts folder, otherwise the unlink command throws out an error:
and the delete.php:
Now the listing and deleting system works as well BUT I HAVE to put the list.php and the delete.php in the posts folder, otherwise the unlink command throws out an error:
The list.php is this:Warning: unlink(434567568745457436as.txt) [function.unlink]: No such file or directory in /data/10/1/71/162/1071325/user/24/htdocs/storage/cms/delete.php on line 3
Code: Select all
<?
echo "<form id='form1' name='form1' method='post' action='delete.php'>";
//Looks into the directory and returns the files, no subdirectories
echo "<select name='yourfiles'>";
$dirpath = "/data/10/1/71/162/1071325/user/24/htdocs/storage/cms/posts";
$dh = opendir($dirpath);
while (false !== ($file = readdir($dh))) {
//Don't list subdirectories
if (!is_dir("$dirpath/$file")) {
echo "<option value='$file'>$file</option>";
}
}
closedir($dh);
//Close Select
echo "</select>";
echo "<input type='submit' name='Submit' value='Delete' /></form>";
?>Code: Select all
<?
$myFile = $_POST['yourfiles'];
unlink($myFile);
echo "<center>file: $myFile was deleted";
echo "<br><br><a href='list.php'>Go back to list</a></center>";
?>