Forum Moderators: coopster
<!----------PHP CODE STARTS HERE -->
<?php
$wdir = $_GET['dir'];
// set variable to allow for image per row control
$row = 0;
$dhandle = opendir($wdir."/main");
/* loop over the directory. */
while (false!== ($file = readdir($dhandle)))
{
if ( $file!= "." ¦¦ $file!= "..")
{
echo "<td>";
echo "<a href=\"$wdir/main/$file\"><img
src=\"$wdir/thumb/$file\"></a>";
echo "</td>";
$row =$row + 1;
if ( $row == 4 )
{
echo "</tr> <tr>";
$row = 0;
}
}
}
?>
<!----------PHP CODE ENDS HERE ---->
if ( $file!= "." ¦¦ $file!= "..")
i changed to this as i saw on php.net. and it works. but i dont get it....can anyone explain me how please? the way i understand it, the first method seems to be right. i mean as long as the file read is not "." or ".." do whatever. while the method below says if the file is not . AND .. do whatever. THe reason it confuses me is that its looping trough the files in the directory so when it reaches . it wont print. then the next is .. and it shouldnt print either rite?
thanks for any explenation
if ( $file!= "." && $file!= "..")
kumar
these exist in every directory
you don't want to include a link to either of them
scenario 1
if ( $file!= "." ¦¦ $file!= "..")
the first entry in a dir is .
if $file == . and we hit your if statement
$file!= "." would be false
$file!= ".." would be true
using ¦¦ only one of the tests needs to return true therefore we now have a link to the present directory
the second entry in a dir is ..
if $file == .. and we hit your if statement
$file!= "." would be true
$file!= ".." would be false
using ¦¦ only one of the tests needs to return true therefore we now have a link to the parent directory
scenario 2
if ( $file!= "." && $file!= "..")
if $file == . and we hit the new if statement
$file!= "." would be false
$file!= ".." would be true
returns false because both tests are not true
if $file == .. and we hit the new if statement
$file!= "." would be true
$file!= ".." would be false
again returns false because both tests need to be true
We now end up with no link to current dir or parent dir