1

我正在研究一种通过 php 列出目录中所有文件的简单方法。我有直接来自 php.net 的代码,但我似乎无法访问符号链接。当我尝试访问符号链接(到目录)时,getcwd() 将显示原始工作目录。

index1.php 是这个文件。我在arch linux上运行。

ls -lh的目录。权限似乎是有序的?

[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代码部分:

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

产生:

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

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

有没有人有任何想法或建议?我原以为这会奏效......

4

1 回答 1

0

尝试使用readlink() 您应该能够将链接转换为目录...并使用is_link()来验证它是否真的是一个 =)

于 2012-11-14T01:53:29.653 回答