note 62174 deleted from function.opendir by nlopess
| From: | nlopess@php.net | Date: | Tue, 21 Feb 2006 22:30:47 +0000 |
| Subject: | note 62174 deleted from function.opendir by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-104168@lists.php.net to get a copy of this message | ||
Note Submitter: darksage2727 at hotmail dot com
----
My index.php, just parses the content of the directory it's in and shows it in a table. Also
has an upload function, but you can turn if off.
<?php
//Settings
$allow_del = 0;
$allow_upload = 1;
//html
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n\"http://www.w3.org/TR/html4/strict.dtd\">\n
<html>\n <head>\n <title>Why are you here?!? IP: " .
$_SERVER["REMOTE_ADDR"] . "</title>
<meta http-equiv=\"content-type\"
content=\"text/html;charset=ISO-8859-1\">\n";
/* Add to exclude in Dir Listing
(!ereg(".php", $f )) //Extension
($f != "index.php" ) //File */
//Delete
if ($_GET['del'] != "" && $allow_del == 1) {
@unlink($_GET['del']); }
//Upload
if (!empty($_FILES)) {
if (!@fopen( "./UPLOADS/{$_FILES['file'] ['name']}", "r" ))
{
move_uploaded_file ($_FILES['file']
['tmp_name'],"./UPLOADS/{$_FILES['file'] ['name']}")
or die( "could not upload file!: " );
echo "File uploaded! :D - <a href='./UPLOADS/" .
$_FILES['file']['name'] .
"'/>View/Download</a><br><hr>";
} else {
echo "File already existed! Not uploaded. :<<br><hr>";
}
}
//Color Settings
$font_color = "black";
$font_size = "12";
$link_color = "black";
$hl_color = "white";
$bg_color = "#D3D3D3";
//CSS
echo " <style type=\"text/css\">
a:link {text-decoration: none; color: " . $link_color . ";}
a:visited {text-decoration: none; color: " . $link_color . ";}
a:active {text-decoration: none; color: " . $hl_color . ";}
a:hover {text-decoration: none; color: " . $hl_color . "}
body {background-color: " . $bg_color . "; color: " . $font_color . ";
text-align: center; font-family: courier, serif;}
table {text-align: left; position: relative; z-index: 1; width: 600px; margin: 20px auto 20px
auto; overflow: auto; padding: 2px; border: 1px solid " . $font_color . "; font-size:
" . $font_size . "px; color: " . $font_color . ";}
</style>\n </head>\n"
. " <body>\n";
echo "Hello, " . $_SERVER['REMOTE_ADDR'];
echo "<hr>Directory: " . $_SERVER['REQUEST_URI'];
//Directory Listing
$hdir = opendir ("./");
$i = 0;
while ($f = readdir($hdir)) {
$i++;
$file[$i] = $f;
}
$i = 0;
echo " <table>\n <tr>\n";
echo " <td></td>\n";
echo " <td>Filename:</td>\n";
echo " <td>Type:</td>\n";
echo " <td>Last Update:</td>\n";
echo " <td>Size:</td>\n";
if ($allow_del == 1) { echo " <td>Options:</td>\n </tr>\n"; }
foreach ( $file as $f ) {
if (($f != "index.php" )) {
echo " <tr>\n <td>";
if (is_dir("$f")) {
echo "<img src='http://img454.imageshack.us/img454/9497/folder8bk.gif'>";
} else {
echo "<img src='http://img454.imageshack.us/img454/9411/generic6ue.gif'>";
}
echo "</td>\n <td><a
href='$f'>$f</a></td>\n";
$type = split( "[/.]", $f );
if (is_dir("$f")) {
echo " <td>Folder</td>\n";
} else {
echo " <td>" . strtoupper($type[1]) . "</td>\n";
}
echo " <td>" . date( "m-d-y @ H:i:s", filectime($f)) .
"</td>\n";
echo " <td>" . round( filesize( $f ) / 1024 ) . " KB</td>\n";
if ($allow_del == 1) { echo " <td><a href='index.php?del=". $f .
"'>Delete</a></td>\n"; }
echo " </tr>\n";
}
}
closedir($hdir);
echo " <hr>\n";
//Upload Code
if ($allow_upload == 1) { echo " </table>\n <hr><form method='POST'
enctype='multipart/form-data' action='index.php'><p>Upload:<input
type='file' name='file'><input type='submit'
value='Upload'></p></form>\n"; }
echo "<p><hr>" .$_SERVER['SERVER_SOFTWARE'] . " at Port "
. $_SERVER['SERVER_PORT'];
//End Tags
echo "</body>\n</html>";
?>