【问题标题】:PHP opendir issuePHP opendir问题
【发布时间】:2012-05-09 19:15:33
【问题描述】:

为什么即使目录存在,我也会收到此错误?如果我以父目录为目标,它工作正常,我也尝试使用 %20 而不是空间,并尝试删除最后一个 / 但没有任何效果!

警告: opendir(/home/xxxx/user_files/users/xxxx/test directory/) [function.opendir]: failed to open dir: No such file or directory in / home/xxxx/public_html/beta/stream._pages/file._list._i.php 第 54 行

(注意:xxxx只是我在审查用户名)

【问题讨论】:

  • 目录名中的空格好像有问题。如何使其允许使用空格?
  • 我认为您的网址中缺少 public_html。
  • /home/xxxx/user_files/users/xxxx/test directory/ 对我来说似乎不是正确的路径。
  • 不,我没有错过public_html,user_files目录在public_html的外面。我可以正常访问 /home/xxxx/user_files/users/xxxx/nospace//home/xxxx/user_files/users/xxxx/,但不能访问 /home/xxxx/user_files/users/xxxx/测试目录/
  • 目录物理存在吗?

标签: php opendir


【解决方案1】:

对于任何试图在 public_html 文件夹之外查找文件夹的人。

此代码由 php.net 为opendir() 函数提供:

if ( $handle = opendir('../../../../') )
{
    echo "Directory handle: $handle\n";
    echo "Entries:\n";

    /* This is the correct way to loop over the directory. */
    while ( false !== ( $entry = readdir( $handle ) ) )
    {
        echo "$entry\n";
    }

    /* This is the WRONG way to loop over the directory. */
    while ($entry = readdir($handle))
    {
        echo "$entry\n";
    }

    closedir( $handle );
}

解决方案

$handle 我开始检查'../' 可以返回多远,添加尽可能多的 ../ 直到你找到你需要的文件夹。我猜你从那里开始。

对我来说'../../../../' 已经足够了,每台服务器都不同。

【讨论】:

    【解决方案2】:

    创建一个名为 test.php 的文件并将其放在您的测试目录中。在该文件中,输入以下代码:

    <? echo dirname(__FILE__);?>
    

    然后,在您的网络浏览器中访问测试目录/test.php,复制并粘贴 test.php 中给出的路径,然后尝试在 opendir 中使用该确切路径。

    另一个问题可能是你的目录权限不对,试试chmodding到777

    【讨论】:

    • 是的,我想到了,但该文件夹不在 public_html 下。也许他可以通过 ssh + php CLI 做到这一点。
    • 是的...我无法通过浏览器访问它来执行此操作。通过 SSH 执行的命令是什么?
    • 我尝试通过 ssh 执行 cd 'test directory',但它不起作用,尽管我也可以在这里执行 cd nospacesmh
    • 唉,用 \ 替换空格不适用于 opendir。 :'(
    • SOOOOOO.... 原来这是一个错字。该目录被称为'test driectory' facepalm
    猜你喜欢
    • 2011-12-09
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    • 2011-09-23
    • 1970-01-01
    相关资源
    最近更新 更多