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
php_seth
Forum Newbie
Posts: 5 Joined: Sat Jan 24, 2004 8:49 pm
Location: Minneapolis, MN
Post
by php_seth » Sat Jan 24, 2004 8:49 pm
i'm a newb. take pity..
Code: Select all
<ul>
<?
$dir = opendir("../photos/");
while (false != ($file = readdir($dir))) {
if (is_dir($file) && $file !== '.' && $file !== '..') {
echo "<li><a href="../photos/$file" title="$file">$file</a></li>";
}
}
closedir($dir);
?>
</ul>
displays nothing while the same thing with the "is_dir($file)" condition removed from that if statement displays a list of the contents of the folder, dirs and files alike.
Gen-ik
DevNet Resident
Posts: 1059 Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.
Post
by Gen-ik » Sun Jan 25, 2004 12:34 am
Try this...
Code: Select all
<?php
$dir = opendir("../photos/");
while (false !== ($file = readdir($dir)))
{
if(is_dir($file) && $file != "." && $file != "..")
{
echo "<li><a href="../photos/$file" title="$file">$file</a></li>";
}
}
closedir($dir);
?>
I take it you're trying to echo() a list of folders?
If your trying to echo() image files then change
is_dir($file) to
!is_dir($file) and remove the
&& $file != "." && $file != ".." bit.
php_seth
Forum Newbie
Posts: 5 Joined: Sat Jan 24, 2004 8:49 pm
Location: Minneapolis, MN
Post
by php_seth » Sun Jan 25, 2004 1:08 am
that isn't working either.
i don't understand why though.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sun Jan 25, 2004 2:41 am
With is_dir($file) .. $file is ONLY a filename, it has no path part.
So you probably want to be checking is_dir('../photos/'.$file)
php_seth
Forum Newbie
Posts: 5 Joined: Sat Jan 24, 2004 8:49 pm
Location: Minneapolis, MN
Post
by php_seth » Sun Jan 25, 2004 3:18 am
yeah, i tried that too, and still nothing.
gah!
Gen-ik
DevNet Resident
Posts: 1059 Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.
Post
by Gen-ik » Sun Jan 25, 2004 8:23 am
I was a wee bit tired last time I replied and I completely overlooked something. Try this...
Code: Select all
<?php
$dir = opendir("../photos"); // Removed trailing forward slash
while (false !== ($file = $dir->read())) // made a change here
{
if(is_dir($file) && $file != "." && $file != "..")
{
echo "<li><a href="../photos/$file" title="$file">$file</a></li>";
}
}
$dir->close(); // made a change here
?>
php_seth
Forum Newbie
Posts: 5 Joined: Sat Jan 24, 2004 8:49 pm
Location: Minneapolis, MN
Post
by php_seth » Sun Jan 25, 2004 8:39 pm
what does -> mean?
php_seth
Forum Newbie
Posts: 5 Joined: Sat Jan 24, 2004 8:49 pm
Location: Minneapolis, MN
Post
by php_seth » Sun Jan 25, 2004 8:42 pm
Fatal error: Call to a member function on a non-object in /home/sethras/public_html/v2/_port_photo.php on line 17
Code: Select all
while (false !== ($file = $dir->read())) // made a change here
Gen-ik
DevNet Resident
Posts: 1059 Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.
Post
by Gen-ik » Mon Jan 26, 2004 8:55 am
You are creating an OBJECT when you set the directory using opendir() and the -> will be calling a variable or function from that OBJECT.
:: [php_man]dir[/php_man]