1

I'm working on a simple means of listing all files in a directory via php. I have code directly from php.net which does this, but I seem to have trouble accessing symbolic links. When I try to access a symbolic link (to a directory), getcwd() will display the original working directory.

index1.php is the file for this. I am running on arch linux.

ls -lh of directory. permissions appear to be in order?

[drake@unimatrix434 .hiddenVideo]$ pwd
/home/drake/public_html/.hiddenVideo
[drake@unimatrix434 .hiddenVideo]$ ls -lh
total 224K
-rw-r--r-- 1 drake users  921 Nov 13 20:17 index1.php
-rwxr-xr-x 1 drake users 213K Nov 13 15:19 index.php
drwxr-xr-x 2 drake users 4.0K Nov 13 20:05 testDIR
lrwxrwxrwx 1 drake users   26 Nov 13 14:10 Video -> /media/storage_pool/Video/

php code section:

<?php
    echo "<div>" . getcwd() . "</div>";
    chdir('Video');
    echo "<div>" . getcwd() . "</div>";

    echo "</br>";

    //list files
    if ($handle = opendir('.')) {
        echo "<div>Directory handle: $handle</div>";
        echo "<div>Entries:</div>";

        while (false !== ($entry = readdir($handle))) {
            echo "<div>$entry</div>";
        }
        closedir($handle);
    }
?>

Which yields:

/home/drake/public_html/.hiddenVideo
/home/drake/public_html/.hiddenVideo

Directory handle: Resource id #3
Entries:
..
index.php
.
Video
index1.php
testDIR

Does anyone have any ideas or suggestions? I would have thought this would work...

1 Answer 1

0

Try with readlink() You should be able to transform the link into the dir... and use is_link() to verify if it actually is one =)

1
  • Make sure you are using FULL PATH
    – Manatax
    Commented Nov 14, 2012 at 2:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.