I have written this simple script display all the files in a directory as a set of buttons.
This code reads from the upload directory and displays all files inside a submit button in a form.
$handle = opendir("upload");
echo '<form name="form" method="post" action="download.php">';
while($name = readdir($handle)) {
echo '<input type="submit" name="file" value='.$name.' />';
}
echo '</form>';
Now the issue here is; every time I run the script I find two button at the beginning with contents . and ..
I have not been able to figure out what causes this issue.
What you have encountered are two special files used by the file system.
.represents the current directory you are in.1..represents the parent directory of the current directory.2Footnotes:
1. A path such as “/my_dir/././././././file” is equivalent to “/my_dir/file”.
2. A path such as “/my_dir/../my_dir/../my_dir/file” is equivalent to “/my_dir/file” since
..will make you move “up” one level.To get around the issue of showing these two to your user filter the content returned by
readdirusing something as the below: