2

I want to open a directory on linux file system using the opendir() PHP function.

The path might contain spaces or some other special characters.

While I am trying to open the directory I get:

Warning: opendir(/home/user/_demo/test/salamis\ test): failed to open dir: No such file or directory

I firstly tried to replace the space character with \ (slash space) using:

str_replace(" ","\ ","salamis test");

But unfortunately is not working. Any suggestions?

glarkou
  • 7,023
  • 12
  • 68
  • 118

2 Answers2

0

Same problem today. I found that adding the quotes did not help. I realized that the share folder was mounted with a different user account, and after umounting and updating /etc/fstab with the correct uid & gid (apache), I was able to mount and process files on the share.

This answer was also helpful.

Community
  • 1
  • 1
a coder
  • 7,530
  • 20
  • 84
  • 131
0

Enclose path parameter within quotes (double or single).

e.g.

opendir('/home/user/_demo/test/salamis test');
opendir("/home/user/_demo/test/salamis test");

$path = '/home/user/_demo/test/salamis test';
opendir($path);

$path = "/home/user/_demo/test/salamis test";
opendir($path);    
ThinkingMonkey
  • 12,539
  • 13
  • 57
  • 81