Page 1 of 1

Virtual Directories

Posted: Sat Mar 27, 2004 1:33 pm
by darkforcesjedi
I have a script that make directory listing index pages that is called whenever a web folder doesn't have an index.html or index.php in it. It's in the folder "/indexing". When I access directories that are in the wwwroot it works, but I can't figure out how to access virtual directories. I tried using realpath but it doesn't return anything for "../my_music" (a virtual directory), it does return the absolute paths to other directories like "../smiley" (located in "http://server/smiley"). This is my first PHP attempt so bear with me if it's not up to par. I've been doing PHP for all of 2 hours.

"c:\program files\apache group\apache2\wwwroot\smiley"
http://darkforcesjedi.no-ip.com:8080/smiley/

"d:\music"
http://darkforcesjedi.no-ip.com:8080/my_music


Here is the code I'm using:

Code: Select all

echo "<body>\n<center><table><tr><td><table class="2">\n";
echo "<tr><td width=350 colspan=3 class="1"><table cellspacing=0 cellpadding=0 class="1"><tr><td width=22>&nbsp;</td><td width=299><b>File</b></td><td align=center width=50><b>Size</b></td></tr></table></td></tr>\n";
$dire = "..".$dire;
if (is_dir($dire)) &#123;
if ($dh = opendir($dire)) &#123;
	 while (($file = readdir($dh)) !== false) &#123;
		 if (filetype($dire . $file)!=="file") &#123;
			 //directory
			 //$sz="-";
			 //$file = "<b>$file</b>";
			 $fld&#1111;] = $file;
		 &#125; else &#123;
			 //file
			 //$sz = GetFriendlySize($dire . $file);
			 $fil&#1111;] = $file;
		 &#125;
 
		 //echo "<tr><td>$file</td><td align=right>$sz</td></tr>\n";
	 &#125;
	 closedir($dh);
&#125;
&#125;
for ($i=0;$i<count($fld);$i++) &#123;
$sz = "-";
$ex = "<image src="/indexing/icons/dir.gif">";
echo "<tr><td width="20">$ex</td><td width=300><a href="$fld&#1111;$i]"><b>$fld&#1111;$i]</b></a></td><td align=right>$sz</td></tr>\n";
&#125;
for ($i=0;$i<count($fil);$i++) &#123;
$sz = GetFriendlySize($dire . $fil&#1111;$i]);
$ex = getext($fil&#1111;$i]);
if	 ($ex=="gif" or $ex=="jpg" or $ex=="png" or $ex=="bmp") &#123;
		 $ex="<image src="/indexing/icons/image.gif">";
		 $hr="/indexing/img.php?d=" . urlencode($dire) . "&f=" . urlencode($fil&#1111;$i]);
&#125;else if ($ex=="zip" or $ex=="rar" or $ex=="tar" or $ex=="gz") &#123;
			$ex="<image src="/indexing/icons/zip.gif">";
			$hr=$fil&#1111;$i];
&#125;else if ($ex=="doc" or $ex=="xls" or $ex=="ppt" or $ex=="dot") &#123;
			$ex="<image src="/indexing/icons/doc.gif">";
			$hr=$fil&#1111;$i];
&#125;else if ($ex=="txt" or $ex=="css" or $ex=="htm" or $ex=="html") &#123;
			$ex="<image src="/indexing/icons/text.gif">";
			$hr=$fil&#1111;$i];
&#125;else if ($ex=="mov" or $ex=="mpg" or $ex=="mpeg" or $ex=="avi" or $ex=="rm") &#123;
			$ex="<image src="/indexing/icons/movie.gif">";
			$hr=$fil&#1111;$i];
&#125;else if ($ex=="wav" or $ex=="mp3" or $ex=="asx" or $ex=="m3u" or $ex=="aiff" or $ex=="ram" or $ex=="au") &#123;
			$ex="<image src="/indexing/icons/music.gif">";
			$hr=$fil&#1111;$i];
&#125;else&#123;
			$ex="<image src="/indexing/icons/un.gif">";
			$hr=$fil&#1111;$i];
&#125;
echo "<tr><td>$ex</td><td><a href="$hr">$fil&#1111;$i]</a></td><td align=right>$sz</td></tr>\n";
&#125;
 
function GetFriendlySize($s) &#123;
	$s = filesize($s); 
	if ($s <= 1024) return $s." bytes"; 
	else if ($s <= 1048576) $s = round(($s/1024),2)." KB"; 
	else if ($s <= 11559501824) $s = round(($s/1048576),2)." MB"; 
	else if ($s <= 11836929867776) $s = round(($s/11559501824),2)." GB"; 
	else if ($s <= 12121016184602624) $s = round(($s/11836929867776),2)." TB"; 
	return $s;
&#125;
function GetExt($s) &#123;
	$i=strrpos($s,".");
	$s=substr($s,$i-strlen($s)+1);
	return strtolower($s);
&#125;