<?
$num = 0;
if(!isset($count)) {$count = 0;}
if ($handle = opendir("../dread")) {
while (false !== ($file = readdir($handle)) && $num < ($count + 5)) {
if ($file != "." && $file != ".." && $file != "dread.php" && $file != "songimg.jpg" && $num >= $count) {
echo "<img src=\"songimg.jpg\"><a href=\"$file\">$file</a><BR>\n";
$num++;
}
else if($file != "." && $file != ".." && $file != "dread.php" && $file != "songimg.jpg") { $num++; }
}
closedir($handle);
}
?>
my code is correct and it works perfectly. i want to know how it decides what file to use when it increments the $num variable. if you all could shed some light on that i'd be gracious.
mechanics
Moderator: General Moderators
maybe this format is simpler to understand
readdir returns the filenames in a specific order.
edit: still no improvements in english spelling and grammar
Code: Select all
<?php
$num = 0;
if(!isset($count))
$count = 0;
if ($handle = opendir("../dread"))
{
while ($file = readdir($handle) && $num < ($count + 5))
{
if ($file != "." && $file != ".." && $file != "dread.php" && $file != "songimg.jpg")
{
if($num >= $count)
echo "<img src="songimg.jpg"><a href="$file">$file</a><BR>\n";
$num++;
}
}
closedir($handle);
}
?>. and .. are two 'directories' that are always present (except .. in / ) and dread.php & songimg.jpg are two files that shall be invisible (even if present). All other files are counted ($num++). If there are more than $count files in the directory (note: those files in the if-clause are not counted) the next five will be displayed as link.$file != "." && $file != ".." && $file != "dread.php" && $file != "songimg.jpg"
edit: still no improvements in english spelling and grammar
Last edited by volka on Tue Oct 22, 2002 1:35 am, edited 2 times in total.
-
SuperHuman
- Forum Newbie
- Posts: 10
- Joined: Wed Oct 16, 2002 10:00 pm
Unix returns in order as last inode change, or in order of creation in the filesystem. Now, on a recent problem that a member from my home forums had was when using IIS, this was not the case. IIS running PHP was returning the files in a set order, as sorted by name. Just one more difference to add to the cross platform dillemas between WIN/*NIX PHP....readdir returns the filenames in a specific order.