Frank
08-12-2004, 06:19 PM
I turn to the few that helped me with my PHP before to help me again
This function needs to create a vertical, alphabetically sorted list of all JPG, GIF and PNG files in a directory, and output it to html links.
right now, if you go to http://www.dreamwill.net/images/list.php, it will list it by last updated date, and doesnt run any checks for extension. I
dont want that. I got it from Ray, the owner of themaxx.com, so it was the way HE wanted it.
I'm working offline with a test copy (the code below), but its giving me :
Parse error: parse error, unexpected $end in c:\inetpub\wwwroot\test\list.php on line 99
what am I not seeing here...
<?php
$baseUrl = "http://www.dreamwill.net/";
$baseUrl .= "images/";
// outputs the html links.. this is the part you're probably most interested in.
function outputFileList( $dir ) {
$fileList = array();
$gif = 1;
$jpg = 1;
$png = 1;
$index = 0;
$dir = opendir(".");
// builds an associative array of files indexed by modification time
// so we can sort them accordingly. (i'm not actually 100 percent certain
// that this works quite right, but for my purposes it's close enough. probably
// shouldn't use it for controlling a nuclear device or for someone's heart monitor.
while( ($file = readdir($dir)) ) {
if ($file != "." and $file != "..") {
$myfile = explode (".", $file); // test whether is a gif file
// test extensions!
if($gif) {
if($myfile[1] == 'gif' || $myfile[1] == 'GIF') // if it's a gif file
{
$fileList[$index] = $file; // then add it to the array
$index ++;
}
}
if($jpg) {
if($myfile[1] == 'jpg' || $myfile[1] == 'JPG') // if it's a gif file
{
$fileList[$index] = $file; // then add it to the array
$index ++;
}
}
if($png) {
if($myfile[1] == 'png' || $myfile[1] == 'PNG') // if it's a gif file
{
$fileList[$index] = $file; // then add it to the array
$index ++;
}
}
}
// sort the array by key (modification time)
sort($fileList);
// // css class (alternates on each row)
// $class = "oddfile";
// counter used to limit the number of items output.
$num = 0;
// iterate over the list
while ((list ($key, $val) = each ($fileList)) && $num < 100 ) {
// alternate css class
$class = ($class == "oddfile") ? "evenfile" : "oddfile";
// keep track of how many we've output
$num++;
// get the filesize for the tooltip
$filesize = filesize($path."/".$val);
$filename = urldecode($val);
// output the link.
// i'm doing a bit of string manipulation here to translate the image filename into
// the name of the corresponding php file. you'll want to tweak this to your needs.
echo '<span style="margin-right:10px;" class="' . $class . '">' . $num . '</span>';
?><a href="<?php echo $baseUrl ?><?php echo str_replace( "images", "pages", $path ) ?>/<?php echo $val ?>" title="<?php echo urldecode($val)?> : <?php echo urldecode($filesize)?> bytes" class="<?php echo $class?>"><?php echo substr($val, 0, 30)?></a><br>
<?php
}
}
?>
This function needs to create a vertical, alphabetically sorted list of all JPG, GIF and PNG files in a directory, and output it to html links.
right now, if you go to http://www.dreamwill.net/images/list.php, it will list it by last updated date, and doesnt run any checks for extension. I
dont want that. I got it from Ray, the owner of themaxx.com, so it was the way HE wanted it.
I'm working offline with a test copy (the code below), but its giving me :
Parse error: parse error, unexpected $end in c:\inetpub\wwwroot\test\list.php on line 99
what am I not seeing here...
<?php
$baseUrl = "http://www.dreamwill.net/";
$baseUrl .= "images/";
// outputs the html links.. this is the part you're probably most interested in.
function outputFileList( $dir ) {
$fileList = array();
$gif = 1;
$jpg = 1;
$png = 1;
$index = 0;
$dir = opendir(".");
// builds an associative array of files indexed by modification time
// so we can sort them accordingly. (i'm not actually 100 percent certain
// that this works quite right, but for my purposes it's close enough. probably
// shouldn't use it for controlling a nuclear device or for someone's heart monitor.
while( ($file = readdir($dir)) ) {
if ($file != "." and $file != "..") {
$myfile = explode (".", $file); // test whether is a gif file
// test extensions!
if($gif) {
if($myfile[1] == 'gif' || $myfile[1] == 'GIF') // if it's a gif file
{
$fileList[$index] = $file; // then add it to the array
$index ++;
}
}
if($jpg) {
if($myfile[1] == 'jpg' || $myfile[1] == 'JPG') // if it's a gif file
{
$fileList[$index] = $file; // then add it to the array
$index ++;
}
}
if($png) {
if($myfile[1] == 'png' || $myfile[1] == 'PNG') // if it's a gif file
{
$fileList[$index] = $file; // then add it to the array
$index ++;
}
}
}
// sort the array by key (modification time)
sort($fileList);
// // css class (alternates on each row)
// $class = "oddfile";
// counter used to limit the number of items output.
$num = 0;
// iterate over the list
while ((list ($key, $val) = each ($fileList)) && $num < 100 ) {
// alternate css class
$class = ($class == "oddfile") ? "evenfile" : "oddfile";
// keep track of how many we've output
$num++;
// get the filesize for the tooltip
$filesize = filesize($path."/".$val);
$filename = urldecode($val);
// output the link.
// i'm doing a bit of string manipulation here to translate the image filename into
// the name of the corresponding php file. you'll want to tweak this to your needs.
echo '<span style="margin-right:10px;" class="' . $class . '">' . $num . '</span>';
?><a href="<?php echo $baseUrl ?><?php echo str_replace( "images", "pages", $path ) ?>/<?php echo $val ?>" title="<?php echo urldecode($val)?> : <?php echo urldecode($filesize)?> bytes" class="<?php echo $class?>"><?php echo substr($val, 0, 30)?></a><br>
<?php
}
}
?>