Can someone edit this script?

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
stuntedheight
-


Joined: 08 Nov 2003
Posts: 42

PostPosted: Mon May 10, 2004 3:58 am    Post subject: Can someone edit this script? Reply with quote

Can someone please edit the script to hide files named index*.php. * being a number and a wild card. This is going to be used for themes on my site.

Code:



<?php

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

$textcolor = "#000000";           #TEXT COLOUR
$bgcolor = "#b0b0b0";             #PAGE BACKGROUND COLOUR

$normalcolor = "#ffffff";         #TABLE ROW BACKGROUND COLOUR
$highlightcolor = "#e0e0e0";      #TABLE ROW BACKGROUND COLOUR WHEN HIGHLIGHTED
$headercolor = "#e0e0e0";         #TABLE HEADER BACKGROUND COLOUR
$bordercolor = "#000000";         #TABLE BORDER COLOUR
$embed = "images/gif.gif"

?>
<html>
<head>
<title>200mg Files: <? 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}
//-->
</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") {
        #add directory array
        $dirs[] = $file . "/";
      }
      else {
        $files[] = $file;
      }
    }
  }
closedir($handle);
}
@natcasesort($dirs); @natcasesort($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\">File</td><td id=\"bottomborder\" width=\"50\">Size</td><td id=\"bottomborder\" width=\"120\" nowrap>Date Modified</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>";
?>
</body>
</html>


Thank you in advance
_________________
http://www.200mg.net
Back to top View user's profile Send private message AIM Address
digits
-


Joined: 12 May 2004
Posts: 3

PostPosted: Wed May 12, 2004 10:08 pm    Post subject: Reply with quote

Code:
if ($file != "." && $file != ".." && $file != substr($PHP_SELF, -(strlen($PHP_SELF) - strrpos($PHP_SELF, "/") - 1))) {


Code:
if (!preg_match ("/(index.*\.php)/i", $file) && $file != "." && $file != ".." && $file != substr($PHP_SELF, -(strlen($PHP_SELF) - strrpos($PHP_SELF, "/") - 1))) {


This is untested, and I'm not a regex wiz, so use it on your own risk ;P
Back to top View user's profile Send private message Visit poster's website
stuntedheight
-


Joined: 08 Nov 2003
Posts: 42

PostPosted: Sat May 15, 2004 2:13 am    Post subject: Reply with quote

Thank you, it worked. :p
_________________
http://www.200mg.net
Back to top View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group