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/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php