【问题标题】:PHP Opendir() paths containing spaces包含空格的 PHP Opendir() 路径
【发布时间】:2012-02-26 13:07:34
【问题描述】:

我想使用opendir() PHP 函数在linux 文件系统上打开一个目录。

路径可能包含空格或其他一些特殊字符。

当我试图打开我得到的目录时:

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

我首先尝试使用\(斜线空格)替换空格字符:

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

但不幸的是无法正常工作。有什么建议?

【问题讨论】:

  • 你试过opendir("/home/user/_demo/test/salamis test");吗?

标签: php


【解决方案1】:

用引号将路径参数括起来(双引号或单引号)。

例如

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);    

【讨论】:

  • 如果他没有将该路径括在引号中,他会得到一个解析错误。该脚本甚至不会运行。
  • @webbiedave 我猜他在空格前包含了`\`。
  • 死灵评论,但这不是解决方案。它不能解决这个问题。
【解决方案2】:

今天同样的问题。我发现添加引号没有帮助。我意识到共享文件夹是使用不同的用户帐户挂载的,在使用正确的 uid 和 gid (apache) 卸载和更新 /etc/fstab 后,我能够在共享上挂载和处理文件。

This answer 也很有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 2011-05-19
    • 2016-12-05
    • 2011-02-15
    • 1970-01-01
    相关资源
    最近更新 更多