$d = dir("$inputString");
| From: | dave meiners | Date: | Mon, 11 Sep 2000 08:59:47 +0000 |
| Subject: | $d = dir("$inputString"); | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-16133@lists.php.net to get a copy of this message | ||
Can someone maybe tell me what I am doing wrong?
Trying to use a variable for the path of a dir to be
read by php.
dir's found are as listed
/home/httpd/htdocs/Bob Dylan
/home/httpd/htdocs/Led Zep
/home/httpd/htdocs/Pink Floyd
/home/httpd/htdocs/Rolling Stones
/home/httpd/htdocs/Rage Against The Machine
/home/httpd/htdocs/The Who
Links appear as listed
<a href=/index.php?openDir=/Bob+Dylan>Bob Dylan</a>
<a href=/index.php?openDir=/Led+Zep>Led Zep</a>
<a href=/index.php?openDir=/Pink+Floyd>Pink Floyd</a>
<a href=/index.php?openDir=/Rolling+Stones>Rolling
Stones</a>
<a
href=/index.php?openDir=/Rage+Against+The+Machine>Rage
Against The Machine</a>
<a href=/index.php?openDir=/The+Who>The Who</a>
Expected Result is that clicking any one of these
links would print
the dir listing of that dir but it has only worked for
"Rage Against The Machine"
// -- 8< -- 8< -- 8< -- CUT CODE BELOW -- 8< -- 8< --
8< --
<?
$dirPath = "/home/httpd/htdocs";
if ($openDir != ""){
$dirPath = "/home/httpd/htdocs" .
urldecode($openDir);
}
// here we spit out a playlist to winamp with a single
track
// header() tells your browser that this is a
streaming mpeg.
if ($playMp3 != ""){
header( "Content-type: audio/x-mpegurl");
$mp3Path = str_replace("index.php?playMp3=", "",
$REQUEST_URI);
echo "http://$HTTP_HOST". $mp3Path
."\n";
exit;
}
// class returns a sorted array of dir
class DirArray {
function returnArray($inputString)
{
$dirArray = Array();
$d = dir("$inputString");
$dirNum = 0;
while($entry=$d->read()) {
if(is_dir($entry)){
$dirNum++;
if($dirNum > 2){
$dirArray[] = $entry;
}
}
}
$d->close();
sort($dirArray);
return $dirArray;
}
}
class Mp3Array {
function returnArray($inputString)
{
$mp3Array = Array();
$d = dir("$inputString");
while($entry=$d->read()) {
if(strstr("$entry",".mp3")){
$mp3Array[] = $entry;
}
}
$d->close();
natcasesort($mp3Array);
return $mp3Array;
}
}
$newDirArray = new DirArray;
$dirArray = $newDirArray -> returnArray("$dirPath");
$dirCount = count($dirArray);
$newMp3Array = new Mp3Array;
$mp3Array = $newMp3Array -> returnArray("$dirPath");
$mp3Count = count($mp3Array);
?>
<html>
<head>
<title>Hey Now</title>
<style type=text/css>
.dir{font-family:verdana,arial;font-weight:800;font-size:8pt;}
.mp3{font-family:verdana,arial;font-weight:300;font-size:8pt;}
</style>
</head>
<body bgcolor=ffffff>
<table width=100% cellpadding=2 cellspacing=1
border=0>
<?
// print rows for each dir
for($i=0;$i<$dirCount;$i++){ ?>
<tr>
<td class=dir bgcolor=efefef><a
href="/index?openDir=<? echo urlencode($openDir) .
"/" . urlencode($dirArray[$i]); ?>"><? echo
$dirArray[$i]; ?></a></td>
</tr>
<? } ?>
<?
// print rows for each mp3
for($i=0;$i<$mp3Count;$i++){ ?>
<tr>
<td class=mp3 bgcolor=efefef><a
href=/index.php?playMp3=<? echo str_replace(" ",
"%20", urldecode($openDir)) . "/" . str_replace(" ",
"%20", $mp3Array[$i]); ?>><? echo $mp3Array[$i];
?></a></td>
</tr>
<? } ?>
</table>
</body>
</html>
__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/