View Single Post
Join Date: Feb 2008
Posts: 11
Reputation: coffeepot! is an unknown quantity at this point 
Solved Threads: 2
coffeepot!'s Avatar
coffeepot! coffeepot! is offline Offline
Newbie Poster

PHP file reading error

 
0
  #1
Feb 24th, 2008
Hi all,

Can anyone shed any light on this really simple problem please?

I need to read a list of files in a directory on a server. I am using PHP to do something like this...
  1. $counter=0;
  2. if ($handle = opendir($dir)) {
  3. while (false !== ($file = readdir($handle))) {
  4. if ($file != "." && $file != "..") {
  5. $filetype=(pathinfo($file));
I then decide using an if(($filetype[extension]=="txt")||($filetype... to choose what to do with the file.

The problem is this. the readdir($handle) function does not return filenames if the filename has a blank space within its name. So it will read "myfile.txt" okay, but will skip "my file.txt" the problem seems to be the space in the filename because if I manually remove the spaces (from my test files) the function works perfectly well.

Oh and by the way, unfortunately I cannot guarantee file-name consistency in here, so I have to assume there will be names with spaces!

Any suggestions would be really appreciated. thanks in advance, JohnB.
Last edited by MattEvans; Feb 24th, 2008 at 6:40 pm. Reason: Please use code tags
Anything one man can make - another man will try to break.
Reply With Quote