Page 1 of 1

wrong code

Posted: Wed Feb 15, 2006 7:35 pm
by eggnogg
hi, i no very little about php.

Code: Select all

<?PHP
$id=$_REQUEST['idcarro'];
$st="n".$id;

$dir = "./pics/";

if (is_dir($dir)) {
   if ($dh = opendir($dir)) {
        $i=0;
       while (($file = readdir($dh)) !== false) 
       {
            if ( strpos($file,$st) == 0 ) 
            {
                
                $rString .= "&pic".$i."=".$file."&";
                $i++;
                
            }     
           
        }
       closedir($dh);
       
   }
}
echo $rString;

?>
idcarro =17
and there are fotos in the pic directory that start with n17.

can anybody give a quick look at this code and tell me why i'm getting echoed a simple "."? thx!

EDIT: atually, only on the third i increment i start getting the file names...

Posted: Wed Feb 15, 2006 9:15 pm
by josh
. and .. are part of relative paths meaning the current directory and the parent directory. They are returned in file listings. You could also try glob() which I beleive does not display these. Here's the quick fix (straight from the comments in the manual page)

Code: Select all

if (substr($file,0,1)!=".")            //do not look up files or directory's which start with a dot