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

From: Date: Sun, 24 Aug 2008 23:06:08 +0000
Subject: Re: newbie Q: How to say, "if the fileNAME is equal to...", or better yet, "if the fileNAME ends with '.jpg'"?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-278606@lists.php.net to get a copy of this message
But two of those entries are apparently named "." and "..".
Right. That's linux doing that, not php. If you jump into a ssh connection and do an $ ls -la you will see . and .. at the top. if ($filename == '.' || $filename == '..') { continue; }
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).
Because you have: $file = 'xxx.jpg'; That is an assignment. What you want is a comparison: $file == 'xxx.jpg'; Note the double ='s. http://www.php.net/manual/en/language.operators.php In this case, I'd use the pathinfo function to break up the file/path: http://www.php.net/manual/en/function.pathinfo.php -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#278606) next »