newbie Q: How to say, "if the fileNAME is equal to...", or better yet, "if the fileNAME ends with '.jpg'"?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all :-)
It'll be fun to work here with you guys over the coming months. I have been out of the coding loop for 7 years, and I am totally new to PHP, but I should catch up not-too-slowly as I used to code HTML, WebDNA, and a little Visual Basic too. Kindly bear with me.

First Q:
This code does list the files in my dir just fine:

$ThisDir = getcwd()."/thumbs";
$DirHandle = opendir($ThisDir);
if ($DirHandle = opendir($ThisDir)) {
   echo "Directory handle: $DirHandle\n";
   echo "Files:<br /><hr width=\"25\%\" align=\"left\" />";

while ((false !== ($file = readdir($DirHandle))) & 1) {
        	echo "$file<br />";
    }
    closedir($DirHandle);
}

But two of those entries are apparently named "." and "..".
Feel free to enlighten me on that, but, always trying to be self- sufficient, I attempt to workaround by wrapping this line:
echo "$file<br />";
with an if statement that I want to only show the file if it ends with the extension ".jpg". I haven't yet found the 'string.ends_with' function in the docs, so I am just seeing if I can (to learn step by step) instead wrap that echo line with an if statement that says "if the name of the file is equal to (xxxx.jpg)", like so:

$ThisDir = getcwd()."/thumbs";
$DirHandle = opendir($ThisDir);
if ($DirHandle = opendir($ThisDir)) {
   echo "Directory handle: $DirHandle\n";
   echo "Files:<br /><hr width=\"25\%\" align=\"left\" />";

while ((false !== ($file = readdir($DirHandle))) & 1) {
        if (true == ($file="xxxx.jpg")) {
        	echo "$file<br />";
        	}
    }
    closedir($DirHandle);
}

But instead of printing only the name of the file which is equal to "xxxx.jpg", it seems to actually set the value of $file to "xxxx.jpg" on each iteration of the while loop, so what I get is a list of files all having the same name ("xxxx.jpg") and their number is equal to the actual number of files in that dir (plus 2 - for the "." and ".." files).

How to say, "if the fileNAME is equal to...", or better yet, "if the fileNAME ends with '.jpg'"?

Thanks,
-Govinda

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux