We help IT Professionals succeed at work.

opendir Space in path name problem

yahoolane asked
Last Modified: 2008-02-01

   $path = opendir('/home/traxx/public_html/'.$subpath);

if the subpath is something like  "RL 12 11 2006 Audio"

Warning: opendir(/home/traxx/public_html/RL 12 11 2006 Audio/): failed to open dir: No such file or directory in /home/traxx/public_html/movebulk.php on line 20

It is have a problem with the space in the directory name.

What do I need to do to handle Directores with spaces.

This is a Unix system.
Watch Question

Top Expert 2005
This one is on us!
(Get your first solution completely free - no credit card required)
If directory name contains spaces and other strange characters, I would suggest including the name in double quotes.

  $path = opendir('"/home/traxx/public_html/'.$subpath.'"');


snoyes_jw No Joy
Warning: opendir(/home/traxx/public_html/RL\ 12\ 11\ 2006\ Audio/): failed to open dir: No such file or directory in /home/trans/public_html/movebulk.php on line 20

akshak No Joyl
Warning: opendir('/home/traxx/public_html/'.RL 12 11 2006 Audio/): failed to open dir: No such file or directory in /home/traxx/public_html/movebulk.php on line 20
   $path = opendir("'/home/traxx/public_html/'.$subpath");
Notice the dot '.' it really does not like it.

Next solution please.
Hi Yahoolane,

Try following ...

$path = opendir('/home/traxx/public_html/'.htmlspecialchars($subpath));

Please disregard my last comment.  That will not help.

I don't believe having the space is your issue as I tried a directory with spaces and it worked without a hitch.  

Double check to ensure that such a folder exists.  IF it does exist, make sure apache has proper permissions.


The permission are ok,

if I rename the Dir and take out the spaces, it works.

I am useing PHP Version 4.4.1

I think version 5 fixes this problem.

  filectime() also does not work if the file name has a space. so I hope the same solution for that.

Still looking for a solution

Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.