PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
thiscatis
Forum Contributor
Posts: 434 Joined: Thu Jul 20, 2006 11:00 am
Post
by thiscatis » Tue Mar 13, 2007 7:21 am
I'm currently using this code to get the content of a folder.
Code: Select all
<?php
$folder=dir(".");
while($folderEntry=$folder->read()){
echo $folderEntry."<br>";
}
$folder->close();
?>
But it also shows the
.
..
Is there a way to stop those two lines from the output?
Begby
Forum Regular
Posts: 575 Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby » Tue Mar 13, 2007 7:24 am
maybe try an if statement? Like if( $folderEntry != '.' ).....
thiscatis
Forum Contributor
Posts: 434 Joined: Thu Jul 20, 2006 11:00 am
Post
by thiscatis » Tue Mar 13, 2007 7:26 am
Yes, that would be obvious but I thought you can't use that in the WHILE statement?
Begby
Forum Regular
Posts: 575 Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby » Tue Mar 13, 2007 7:29 am
thiscatis wrote: Yes, that would be obvious but I thought you can't use that in the WHILE statement?
Perhaps you should try it.
thiscatis
Forum Contributor
Posts: 434 Joined: Thu Jul 20, 2006 11:00 am
Post
by thiscatis » Tue Mar 13, 2007 7:34 am
Sorry dude,
I tried it some time ago but I used if(!$folderEntry = '.' ),
used if( $folderEntry != '.' ) now and another if clause with if( $folderEntry != '..' )
Works like a charm,
Thanks a lot mate.
Begby
Forum Regular
Posts: 575 Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby » Tue Mar 13, 2007 7:51 am
Excellent!
You can do it like this too instead of using two statements
Code: Select all
<?php
$folder=dir(".");
while($folderEntry=$folder->read()){
if( $folderEntey != '.' && $folderEntry != '..' ) {
echo $folderEntry."<br>";
}
}
$folder->close();
?>
thiscatis
Forum Contributor
Posts: 434 Joined: Thu Jul 20, 2006 11:00 am
Post
by thiscatis » Tue Mar 13, 2007 8:37 am
Is there any way to get this content in a formatted table with a max column?
I had a look with a for loop but didn't get the expected results :s
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 13, 2007 8:50 am
What do you mean by "max column"?
thiscatis
Forum Contributor
Posts: 434 Joined: Thu Jul 20, 2006 11:00 am
Post
by thiscatis » Tue Mar 13, 2007 9:23 am
Instead of getting a list with filenames I would like to have it in a table with a maximum of for e.g. 8 colums
I know how to do this for content from a database but not from files in a folder.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 13, 2007 9:26 am
It's the exact same concept as data from a database.
thiscatis
Forum Contributor
Posts: 434 Joined: Thu Jul 20, 2006 11:00 am
Post
by thiscatis » Tue Mar 13, 2007 9:51 am
I tried to put the for loop with a
Code: Select all
$total_images = count(glob("/MY PATH IS HERE/{*.JPG,*.jpg,*.png}", GLOB_BRACE));
for a file count in the WHILE loop but it keeps looping and not showing any correct tables?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Mar 13, 2007 9:57 am
Are you using the example I posted that's linked from Useful Posts? (The first two links should be of interest.)
thiscatis
Forum Contributor
Posts: 434 Joined: Thu Jul 20, 2006 11:00 am
Post
by thiscatis » Tue Mar 13, 2007 10:49 am
Hey feyd,
yes those are the ones i'm using,
my code:
Code: Select all
//$s_pics is declared before this snippet
$folder=dir("modules/shoots/$s_pics/");
while($folderEntry=$folder->read()){
if( $folderEntry != '.' )
{
if( $folderEntry != '..' ) {
$output .= "<table cellpadding=8 width=100%>\n\n";
$howmany = $count(glob("/MY PATH IS HERE/$s_pics/{*.JPG,*.jpg,*.png}", GLOB_BRACE));; //added dummy path
$rowmax = 3;
for($x = 0; $row = $folderEntry; $x++)
{
if($x % $rowmax == 0)
$output .= "<tr>\n";
$output .= "<td style=\"width: 33%\"><img src=modules/shoots/thumbsup.php?image=$s_pics/$folderEntry&width=225 /></td>";
if($x % $rowmax == $rowmax - 1)
$output .= "\r</tr>\n\n";
}
if($left = (($howmany + $rowmax - 1) % $rowmax))
$output .= '<td colspan="' . $left . '">' . "</td>\n</tr>\n\n";
$output .= "</table>\n\n";
echo $output;
thiscatis
Forum Contributor
Posts: 434 Joined: Thu Jul 20, 2006 11:00 am
Post
by thiscatis » Tue Mar 13, 2007 12:26 pm
could it be with the for loop in the while statement?
thiscatis
Forum Contributor
Posts: 434 Joined: Thu Jul 20, 2006 11:00 am
Post
by thiscatis » Tue Mar 13, 2007 4:49 pm
I'm getting lost here,
now it shows shows the first picture in a formatted table