note 34920 added to function.opendir
| From: | Ultimatedbz at rack1 dot php dot net | Date: | Tue, 12 Aug 2003 03:30:41 +0000 |
| Subject: | note 34920 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53932@lists.php.net to get a copy of this message | ||
How can i disable this function and not allow the user to look at the files above his folder he uses
the following script:
<html>
<head>
<title>Explorer</title>
</head>
<body style='font-size: 10px; line-height: 12px; font-family: Verdana, Arial,
Sans-Serif'>
<p>
<?
if ($_GET['dir']) $folder = $_GET['dir'];
else $folder ='.';
$num=0;
$path = $folder."/";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
$num++; $files[$num] = $file;
}
}
closedir($handle);
print "
<table width=400 cellspacing=0 style='font-size: 10px; line-height: 12px; font-family:
Verdana, Arial, Sans-Serif'>
<tr style='background-color: #BBBBCF;'>
<td style='padding: 2px'>Filename ($num files)</td> <td width=80
align=center>Size</td>
</tr>
<tr>
<td colspan=3 height=2></td>
</tr>
";
while (list ($key, $val) = each ($files)) {
$extension = str_replace(".", "",strrchr($val,'.'));
if (is_dir($path.$val)) $o = "?dir=";
else $o = '';
if (is_dir($path.$val)) $img = 'dir';
elseif (is_file("ext/$extension.gif")) $img = $extension;
else $img = "no";
print "<tr> <td><img width=15 height=15 alt='$extension'
src=ext/$img.gif> <a href='$o$path$val'>$val</a></td><td
align=right>".fsize($path.$val)."</td> </tr>\n";
}
print "
<tr>
<td colspan=3 height=2></td>
</tr>
<tr style='background-color: #BBBBCF;'>
<td colspan=3 height=2></td>
</tr>
</table>
";
?>
</body>
</html>
<?
function fsize($file) {
$a = array("b", "Kb", "Mb", "Gb", "Tb",
"Pb");
$pos = 1;
$size = filesize($file);
$size /= 1024;
return round($size,0)." ".$a[$pos];
}
?>
</html>
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34920
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34920&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34920&report=yes