On Thu, May 12, 2005 7:05 pm, Miguel Vaz said: > > I am having a weird problem with a simple file listing on one of my > client's host. > > My code works perfectly on my host, but if i use the same code on his, it > only lists certain types of files. Heres the code: (i hate hosts that only > allow php inside the cgi-bin dir, its crazy to code like this) > > #!/usr/local/bin/php > <? > $count = 0; > $handle=opendir("/whu1/sites/op158006/public_html/clientes/adagio/"); > while (($file = readdir($handle)) !== false) { > if ($file == "." || $file == ".." || $file == "list.php") { > } else { > if (filetype($file) == "file") { > $size= filesize($file)/1000; > print "$file ($size KB)<br>"; > $count ++; > } else{ echo "They filetype of $file is ", filetype($file), "<br />\n"; } > } > } > closedir($handle); > print "> <b>$count</b> Ficheiro(s)<br>"; > ?> > > This hoster only allows PHP inside the cgi-bin directory. And i can only > list files properly if i list that dir (cgi-bin). I.E. if i use: > > $handle=opendir("/whu1/sites/op158006/cgi-bin/"); > > it lists the dir perfectly, with images or whatever it might have in > there. But if i try to list somje other dir outside the cgi-bin scope list > comes out only with .txt and .php type of files, if i have an image in > there it simply ignores it. > Why does this happen? Its so frustrating! Actually... You need to provide the FULL PATH to filetype, almost for sure: $dir = "/really/long/path/I/should/have/copied/"; $handle = opendir($dir); . . . if (filetype("$dir/$file")){ . . . It only works on the cgi/bin directory because that happens to be the "current working directory" -- the directory you start in. It probably isn't printing the filenames in the "other" directory -- The filenames happen to match up, both in cgi/bin and the other directory, for the files you see... So the readdir() is giving you the filename in the "other" directory, but filetype() is looking at the file in cgi/bin and acting on that one. Any time files in PHP give you trouble, use the FULL PATH to the file. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php