Forum Moderators: coopster

Message Too Old, No Replies

weird links generation

photo album script

         

kumarsena

4:22 am on Jan 15, 2004 (gmt 0)

10+ Year Member



i have the following photo album gernerator emmbedded into a html file. now it works fin, just tha there are two links to the main folder where i keep the original pics and to the thumb folder. how come?

<!----------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 ---->

ergophobe

4:42 pm on Jan 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




if ( $file!= "." ¦¦ $file!= "..")

This will be true under all circumstances, so you will have a link to the current dir and one to the parent dir.

kumarsena

7:10 pm on Jan 15, 2004 (gmt 0)

10+ Year Member



ok that would make sense

any idea how to get around...?

thanks
kumar

kumarsena

7:24 pm on Jan 15, 2004 (gmt 0)

10+ Year Member



well, got it sorted, but it does not make sense to me...this is how it was and this included a link to current and parent folder.

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

too much information

7:24 pm on Jan 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



** oops, misread the question

jatar_k

7:50 pm on Jan 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



. represents the current directory
.. represents the parent directory

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