/ Forside / Teknologi / Udvikling / PHP / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
PHP
#NavnPoint
rfh 3959
natmaden 3372
poul_from 3310
funbreak 2700
stone47 2230
Jin2k 1960
Angband 1743
Bjerner 1249
refi 1185
10  Interkril.. 1146
Fjerne liste filen fra listen
Fra : konsolsiden


Dato : 07-10-04 15:16

Hej, jeg har fundet dette script
http://www.trovaerdig.dk/test/DirectoryListing.php , men problemet er at man
kan se den fil der hedder DirectoryListing.php altså den selv, hvordan kan
man gøre så den ikke viser sig selv, det er også fint nok hvis den bare ikke
viser php filer.
Her har i kildekoden:

<?php
########################################################
# Script Info
# ===========
# File: DirectoryListing.php
# Author: Ash Young (ash@evoluted.net
# Created: 20/12/03
# Modified: 27/09/04
# Website: http://evoluted.net/directorylisting.php
# Requirements: PHP
#
# Description
# ===========
# Displays all files contained within a directory in
# a well formed table, with category-image tags
#
# If you have any functions that you like to see
# implemented in this script then please just send
# an email to ash@evoluted.net
#
# Useage
# ======
#
# To change the colours display when using the script
# scroll down to set up section
#
# To use the script just upload to your server with
# the images and point your browser to the scripts
# filename
#
# SETUP
# =====
#
# Change the following variables to display what colours
# the script outputs
########################################################

DEFINE("IMAGEROOT", "/images/"); #CHANGE /images/ TO THE PATH OF THE
ASSOCIATED IMAGES

$textcolor = "#FFFFFF"; #TEXT COLOUR
$bgcolor = "#535353"; #PAGE BACKGROUND COLOUR

$normalcolor = "#0066FF"; #TABLE ROW BACKGROUND COLOUR
$highlightcolor = "#006699"; #TABLE ROW BACKGROUND COLOUR WHEN
HIGHLIGHTED
$headercolor = "#003366"; #TABLE HEADER BACKGROUND COLOUR
$bordercolor = "#202750"; #TABLE BORDER COLOUR

?>
<html>
<head>
<title>Directory Listings of <? echo $_SERVER["REQUEST_URI"]; ?> </title>
<style type='text/css'>
<!--
body { color: <? echo $textcolor; ?>; font: tahoma, small
verdana,arial,helvetica,sans-serif; background-color: <? echo $bgcolor;
?>; }
table { font-family: tahoma, Verdana, Geneva, sans-serif; font-size: 7pt;
border: 1px; border-style: solid; border-color: <? echo $bordercolor; ?>; }
..row { background-color: <? echo $normalcolor; ?>; border: 0px;}
a:link { color: <? echo $textcolor; ?>; text-decoration: none; }
a:visited { color: <? echo $textcolor; ?>; text-decoration: none; }
a:hover, a:active { color: <? echo $textcolor; ?>; text-decoration: none; }
img {border: 0;}
#bottomborder {border: <? echo $bordercolor;?>;border-style:
solid;border-top-width: 0px;border-right-width: 0px;border-bottom-width:
1px;border-left-width: 0px}
..copy { text-align: center; color: <? echo $textcolor; ?>; font-family:
tahoma, Verdana, Geneva, sans-serif; font-size: 7pt; text-decoration:
underline; }
//-->
</style>
</head>
<body>
<?php
clearstatcache();
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file !=
substr($PHP_SELF, -(strlen($PHP_SELF) - strrpos($PHP_SELF, "/") - 1))) {

if (filetype($file) == "dir") {
//SET THE KEY ENABLING US TO SORT
$n++;
if($_REQUEST['sort']=="date") {
$key = filemtime($file) . ".$n";
}
else {
$key = $n;
}
$dirs[$key] = $file . "/";
}
else {
//SET THE KEY ENABLING US TO SORT
$n++;
if($_REQUEST['sort']=="date") {
$key = filemtime($file) . ".$n";
}
elseif($_REQUEST['sort']=="size") {
$key = filesize($file) . ".$n";
}
else {
$key = $n;
}
$files[$key] = $file;
}
}
}
closedir($handle);
}

#USE THE CORRECT ALGORITHM AND SORT OUR ARRAY
if($_REQUEST['sort']=="date") {
@ksort($dirs, SORT_NUMERIC);
@ksort($files, SORT_NUMERIC);
}
elseif($_REQUEST['sort']=="size") {
@natcasesort($dirs);
@ksort($files, SORT_NUMERIC);
}
else {
@natcasesort($dirs);
@natcasesort($files);
}

#ORDER ACCORDING TO ASCENDING OR DESCENDING AS REQUESTED
if($_REQUEST['order']=="desc" && $_REQUEST['sort']!="size") {$dirs =
array_reverse($dirs);}
if($_REQUEST['order']=="desc") {$files = array_reverse($files);}
$dirs = @array_values($dirs); $files = @array_values($files);

echo "<table width=\"450\" border=\"0\" cellspacing=\"0\"
align=\"center\"><tr bgcolor=\"$headercolor\"><td colspan=\"2\"
id=\"bottomborder\">";
if($_REQUEST['sort']!="name") {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=name&order=asc\">";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=name&order=asc\">";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=name&order=desc\">";
}
}
echo "File</td><td id=\"bottomborder\" width=\"50\"></a>";
if($_REQUEST['sort']!="size") {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=size&order=asc\">";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=size&order=asc\">";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=size&order=desc\">";
}
}
echo "Size</td><td id=\"bottomborder\" width=\"120\" nowrap></a>";
if($_REQUEST['sort']!="date") {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=date&order=asc\">";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=date&order=asc\">";
}
else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?sort=date&order=desc\">";
}
}
echo "Date Modified</a></td></tr>";

$arsize = sizeof($dirs);
for($i=0;$i<$arsize;$i++) {
echo "\t<tr class=\"row\"
onMouseOver=\"this.style.backgroundColor='$highlightcolor';
this.style.cursor='hand';\"
onMouseOut=\"this.style.backgroundColor='$normalcolor';\"
onClick=\"window.location.href='" . $dirs[$i] . "';\">";
echo "\t\t<td width=\"16\"><img src=\"" . IMAGEROOT . "folder.gif\"
width=\"16\" height=\"16\" alt=\"Directory\"></td>";
echo "\t\t<td><a href=\"" . $dirs[$i] . "\">" . $dirs[$i] . "</a></td>";
echo "\t\t<td width=\"50\" align=\"left\">-</td>";
echo "\t\t<td width=\"120\" align=\"left\" nowrap>" . date ("M d Y h:i:s
A", filemtime($dirs[$i])) . "</td>";
echo "\t</tr>";
}

$arsize = sizeof($files);
for($i=0;$i<$arsize;$i++) {
switch (substr($files[$i], -3)) {
case "jpg":
$img = "jpg.gif";
break;
case "gif":
$img = "gif.gif";
break;
case "zip":
$img = "zip.gif";
break;
case "png":
$img = "png.gif";
break;
case "avi":
$img = "move.gif";
break;
case "mpg":
$img = "move.gif";
break;
default:
$img = "what.gif";
break;
}

echo "\t<tr class=\"row\"
onMouseOver=\"this.style.backgroundColor='$highlightcolor';
this.style.cursor='hand';\"
onMouseOut=\"this.style.backgroundColor='$normalcolor';\"
onClick=\"window.location.href='" . $files[$i] . "';\">\r\n";
echo "\t\t<td width=\"16\"><img src=\"" . IMAGEROOT . "$img\" width=\"16\"
height=\"16\" alt=\"Directory\"></td>\r\n";
echo "\t\t<td><a href=\"" . $files[$i] . "\">" . $files[$i] .
"</a></td>\r\n";
echo "\t\t<td width=\"50\" align=\"left\">" .
round(filesize($files[$i])/1024) . "KB</td>\r\n";
echo "\t\t<td width=\"120\" align=\"left\" nowrap>" . date ("M d Y h:i:s
A", filemtime($files[$i])) . "</td>\r\n";
echo "\t</tr>\r\n";
}
echo "</table><div align=\"center\"><a
href=\"http://evoluted.net/directorylisting.php\" class=\"copy\">Directory
Listing Script</a>. <a href=\"http://evoluted.net/\" class=\"copy\">&copy
2003-2004 Ash Young</a></div>";
?>
</body>
</html>


på forhånd tak.

mvh. Eirik.



 
 
Anders Lund (07-10-2004)
Kommentar
Fra : Anders Lund


Dato : 07-10-04 16:00

konsolsiden wrote:
> Hej, jeg har fundet dette script
> http://www.trovaerdig.dk/test/DirectoryListing.php , men problemet er at man
> kan se den fil der hedder DirectoryListing.php altså den selv, hvordan kan
> man gøre så den ikke viser sig selv, det er også fint nok hvis den bare ikke
> viser php filer.
> Her har i kildekoden:

<klip>
if ($file != "." && $file != ".." && $file !=
substr($PHP_SELF, -(strlen($PHP_SELF) - strrpos($PHP_SELF, "/") - 1))) {

Så vidt jeg kan se, burde den med overstående, sortere sig selv fra. Men
ellers skulle nedenstående også kunne gøre det:

Skal have tilføjet: substr($file, -4) != ".php"
Dette vil dog kun virke på .php filer, hvor efternavnet er med små
bogstaver. Det kunne så også (af hvad jeg kan se) gøre at man ikke
behøver hele linien, så den kom til at se sådan ud:

if ($file != "." && $file != ".." && substr($file, -4) != ".php") {

Hvis den skal være beredt på store og små bogstaver, kommer det så til
at se sådan ud:

if ($file != "." && $file != ".." && strtolower(substr($file, -4)) !=
".php") {

Altsammen utestet og ud fra min hullede hukommelse... :)

--
Anders Lund - anders@andersonline.dk
Take back the web - www.mozilla.org/firefox

Nezar Nielsen (07-10-2004)
Kommentar
Fra : Nezar Nielsen


Dato : 07-10-04 17:23

Anders Lund wrote:
> if ($file != "." && $file != ".." && $file !=
> substr($PHP_SELF, -(strlen($PHP_SELF) - strrpos($PHP_SELF, "/") - 1))) {
>
> Så vidt jeg kan se, burde den med overstående, sortere sig selv fra. Men

Især hvis $PHP_SELF bliver erstattet med $_SERVER['PHP_SELF'].

--
Mvh. Nezar Nielsen


Anders K. Madsen (07-10-2004)
Kommentar
Fra : Anders K. Madsen


Dato : 07-10-04 17:44



konsolsiden (07-10-2004)
Kommentar
Fra : konsolsiden


Dato : 07-10-04 19:44

ok, mange tak!



Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408929
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste