Forum Moderators: coopster
i have been thinking about improving my pic album script by including some sort of paging system. now im awasre there are a few tutorials out there, but i would like to do thi from scrathc just to learn. so...
anyone out there who knows if there is a function thta will read the contents of a folder and write it to an array. or do i have to play around and insert into array using a while loop and readdir()? any input would be appreciated.
thanks
kumar
<?
$mydir = "/path/to/dir/";
$d = dir($mydir);
while($entry = $d->read()) {
if ($entry!= "." && $entry!= "..") {
$filearr[] = $entry;
}
}
$d->close();
echo "<ul>";
for each ($filearr as $filename) {
echo "<li>"$filename;
}
echo "</ul>";
?>
the code had a bug but otherwise is working fine.
these two lines (original code) were modified:
for each ($filearr as $filename) {
echo "<li>"$filename;
for some reason the secind line wasnt working, but i couldnt figure out why, just changed it...new code as below
<? $mydir = "mydir";
$d = dir($mydir);
while($entry = $d->read())
{
if ($entry!= "." && $entry!= "..") {
$filearr[] = $entry; }
}
$d->close();
echo "<ul>";
<b>foreach ($filearr as $filename) {</b>
<b> echo $filename;
echo "<br />";</b>
}
echo "</ul>";?>
thanks jatar_k! (i assume its GPL, rite? :) )
hope this is useful some others too...