2

Why do I get this error even though the directory exists? it works fine if I target the parent directory, I tried using %20 instead of space too, and tried removing the last / but nothing works!

Warning: 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 on line 54

(Note: xxxx is just me censoring user names)

CJT3
  • 2,788
  • 7
  • 30
  • 45
  • It seems that there is an issue with spaces in the directory name. How can I make it **ALLOW** the use of spaces? – CJT3 Apr 30 '12 at 02:12
  • I think you are missing public_html in your url. – Taha Paksu Apr 30 '12 at 02:13
  • /home/xxxx/user_files/users/xxxx/test directory/ doesn't seem a right path to me. – Taha Paksu Apr 30 '12 at 02:15
  • no, I am not miss public_html, the user_files directory is **outside** of public_html. I am able to access */home/xxxx/user_files/users/xxxx/nospace/* fine or */home/xxxx/user_files/users/xxxx/*, but not */home/xxxx/user_files/users/xxxx/test directory/* – CJT3 Apr 30 '12 at 02:21
  • does the directory physically exist? – Taha Paksu Apr 30 '12 at 02:23

2 Answers2

0

Make a file called test.php and put it in your test directory. In that file, put this code:

<? echo dirname(__FILE__);?>

Then, visit test directory/test.php in your web browser, copy and paste the path as given in test.php and try using that exact path in opendir.

Another issue might be that the permissions of your directory aren't right, try chmodding to 777

Ali
  • 261,656
  • 265
  • 575
  • 769
  • yea that came to my mind but the folder isn't under public_html. maybe he could do this via ssh + php CLI. – Taha Paksu Apr 30 '12 at 02:25
  • Yeah... I can't access it via the browser to do this. What would the command be to do it via SSH? – CJT3 Apr 30 '12 at 02:29
  • I tried to do `cd 'test directory'` via ssh, but it doesn't work, though I can do `cd nospace` fine here too. *smh* – CJT3 Apr 30 '12 at 02:33
  • allas, replacing spaces with `\ ` doesn't work for opendir. :'( – CJT3 Apr 30 '12 at 02:38
  • did you try running the file test.php? whats the output – Ali Apr 30 '12 at 02:41
  • how do I run the test.php in terminal after I cd? – CJT3 Apr 30 '12 at 02:43
  • Also, I am using a variable when calling the `opendir()` function, so I can't use quotes to escape the path what I am doing looks like this: `opendir($direct)`. – CJT3 Apr 30 '12 at 02:45
  • 3
    SOOOOOO.... it turns out it was a typo. The directory was called 'test driectory' **facepalm** – CJT3 Apr 30 '12 at 02:55
  • @CharlesJohnThompsonIII glad you figured it out :) – Ali Apr 30 '12 at 22:32
0

For anyone trying to find the folder outside of the public_html folder.

This code is provided by php.net for the opendir() function:

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

Solution

The $handle I started checking out how far I could go back with '../' adding as much ../ as possible until you find yourself in the folder you need. From there you take I guess.

For me '../../../../' was enough to get there, it's different on every server.

Matt
  • 136
  • 2
  • 17