RE: HI! can u help me?

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

 



In addition to the opendir() and readdir() there's also the dir() class:
http://us2.php.net/manual/en/class.dir.php

Don't forget to take a look at the script on the readdir() page:

<?php 
if ($handle = opendir('.')) {
   while (false !== ($file = readdir($handle))) { 
       if ($file != "." && $file != "..") { 
           echo "$file\n"; 
       } 
   }
   closedir($handle); 
}
?> 

You need to remember that "." and ".." are condidered directories (aka
folders).

You can also use is_dir() and is_file() to determine if it's a file or a
directory:
http://us2.php.net/manual/en/function.is-dir.php
http://us2.php.net/manual/en/function.is-file.php


And something I never used before but came to my attention recently (yet
another function in a long line of "PHP will already do that"
slap-in-the-forehead things..  The glob() function:
http://us2.php.net/manual/en/function.glob.php

(And now I see in the glob() page, the fnmatch() function too!  Wow.. Is
there anything PHP doesn't do already? Hah)


Looks like with glob(), you can do your image file type matching too.
Maybe something like this (untested):


$filefilter = array("*.jpg","*.gif","*.png");

foreach (glob({implode(",",$filefilter)},GLOB_BRACE) as $filename) {
  if (is_file($filename)) echo "$filename size " . filesize($filename) .
"\n";
}


The note on the glob() page says that it CAN be case sensitive, so you
might need to do "*.jpg" and "*.JPG"


Anyway, some more functions and thoughts to add to what Mike already
offered.

-TG

> -----Original Message-----
> From: Mike [mailto:php@xxxxxxxxxxxx] 
> Sent: Friday, November 26, 2004 5:33 PM
> To: 'Kurlic'; php-windows@xxxxxxxxxxxxx
> Subject: RE:  HI! can u help me?
> 
> 
> Take a look at 
> 
> opendir() http://us2.php.net/manual/en/function.opendir.php
> 
> and 
> 
> readdir() http://us2.php.net/manual/en/function.readdir.php
> 
> Everything that you need is there.
> 
> -M
> 
> > -----Original Message-----
> > From: Kurlic [mailto:kur_mail@xxxxxxxxxxxxx] 
> > Sent: Friday, November 26, 2004 4:14 PM
> > To: php-windows@xxxxxxxxxxxxx
> > Subject:  HI! can u help me?
> > 
> > Hi all!
> > 
> > Can i ask u a question?
> > 
> > Using PHP:
> > How can i count the files in a folder and obtain their names?
> > (i want to produce a script that count the images in a folder 
> > and make a list of them...)
> > 
> > please help me... ^_^
> > 
> > Thank you by Kurlic
> > --------------------
> > Kur_mail@xxxxxxxxxxxxx
> > --------------------
> > 
> > --
> > PHP Windows Mailing List (http://www.php.net/) To 
> > unsubscribe, visit: http://www.php.net/unsub.php
> > 
> 
> -- 
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux