|
Posted by Jerry Stuckle on 09/12/07 12:03
Confused but working on it wrote:
> On 2007-09-11 15:12:16 -0700, Michael Fesser <netizen@gmx.de> said:
>
>> .oO(Confused but working on it)
>>
>>> Now it appears I have files named "." and "..", well, back to the
>>> manual...
>>
>> readdir() returns _all_ directory entries, normal files and other
>> directories. You can use is_file() or is_dir() to filter out the
>> unwanted. See the manual for details and examples.
>>
>> Micha
>
> I got this from the manual:
>
> <?php
> var_dump(is_dir('a_file.txt')) . "\n";
> var_dump(is_dir('bogus_dir/abc')) . "\n";
>
> var_dump(is_dir('..')); //one dir up
> ?>
> The above example will output:
> bool(false)
> bool(false)
> bool(true)
>
> Don't think I need the var dump part.
No, that's showing how is_dir works, not necessarily "live code".
> Below I inserted where I think the
> test should go. Basically read from the directory, test to see if it's a
> dir, if a dir get the next $file, if not echo. I don't think I can
> replace the readdir with the is_dir because the first two items ARE
> directories so I can't tell it to stop if it sees a dir.
> <?php
> //Open images directory
> $dir = opendir("images");
> //List files in images directory
> while (($file = readdir($dir)) !== false)
> {
> // Test for file or directory with is_dir like if $file is a
> directory get the next $file.
> echo "<img src='images/$file'>";
> }
> closedir($dir);
> ?>
>
> I didn't see any very simple examples of get me everything that is a
> ".jpg" type of thing which would work too.
>
> Time for some sleep. :)
>
And you won't find examples for everything you want to do. There are
too many possibilities. You need to get familiar with the language and
function calls so you can look up what you need. I find having a local
copy of the PHP doc (as a windows help file) is quite useful.
To get a file extension, check out
http://us2.php.net/manual/en/function.pathinfo.php
Then you can compare on the extension. Just a warning - if the files
are uploaded by users, don't depend on the extension being correct.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|