Php 未打印实际权限和所有者

Php 未打印实际权限和所有者,php,Php,我正在本地服务器上编写PHP文件管理器。问题是当我转到父目录和子目录时,PHP不会打印实际权限和所有者。 服务器:Apache2 PHP版本:7.3.14 我通过单击“.”转到父目录。 请帮帮我。这是我的密码 <table> <thead> <tr> <th>Name</th> <th>Owner</th> <

我正在本地服务器上编写PHP文件管理器。
问题是当我转到父目录和子目录时,PHP不会打印实际权限和所有者。
服务器:Apache2
PHP版本:7.3.14
我通过单击“.”转到父目录。

请帮帮我。这是我的密码

<table>
    <thead>
        <tr>
            <th>Name</th>
            <th>Owner</th>
            <th>Permission</th>
        </tr>
    </thead>
    <tbody>

<?php
    $cwd = getcwd();

    if(isset($_GET['dir'])) {
        $cwd = $_GET['dir'];
    }

    $fil = scandir($cwd);

    foreach ($fil as $file) {
        $path = realpath($file);
        echo '<tr>';
        if(is_dir($file)) {
            echo '<td><a href=" '.$_SERVER['PHP_SELF'].'?dir='.$path.' ">'.$file.'</a></td>';
            echo '<td>'.posix_getpwuid(fileowner($file))[name].'</td>';
            echo '<td>'.substr(sprintf('%o', fileperms($file)), -3).'</td>';
        }

        else {
            echo '<td><a href=" '.$_SERVER['PHP_SELF'].'?edi='.$path.' ">'.$file.'</a></td>';
            echo '<td>'.posix_getpwuid(fileowner($file))[name].'</td>';
            echo '<td>'.substr(sprintf('%o', fileperms($file)), -3).'</td>';
        }
        echo '<tr>';
    }
?>
    </tbody>
</table>

名称
所有者
许可

Apache用户可能没有读取父目录的权限。您需要确保Apache使用的用户具有目录读取和执行权限。Apache用户通常是www数据

小心:你不想让用户访问他们不应该看到的文件或目录

您可以使用以下命令更改目录组:


chgrp www-data

Apache用户可能没有读取父目录的权限。您需要确保Apache使用的用户具有目录读取和执行权限。Apache用户通常是www数据

小心:你不想让用户访问他们不应该看到的文件或目录

您可以使用以下命令更改目录组:


chgrp www-data

我一直想把这类东西添加到我的网站编辑功能中。我很高兴你帮我开始了。按计划进行以下工作:

echo '
<table width=50%>
    <thead>
        <tr>
            <th width=60%><p>Name</p></th>
            <th width=20%><p>Owner</p></th>
            <th width=20%><p>Permission</p></th>
        </tr>
    </thead>
    <tbody>
';

    $cwd = getcwd();

    if(isset($_GET['dir'])) {
        $cwd = $_GET['dir'];
    }

    $fil = scandir($cwd);

    foreach ($fil as $file) {
        $path = realpath($file);
        $dir = '/'.$file;
        echo '<tr>';
        if($file == '..'){
            $parent = dirname($cwd);
            echo '<td><a href=" '.$_SERVER['PHP_SELF'].'?dir='.$parent.' ">'.$file.'</a></td>';
            echo '<td><p>'.posix_getpwuid(fileowner($file))["name"].'</p></td>';
            echo '<td><p>'.substr(sprintf('%o', fileperms($file)), -3).'</p></td>';
        }
        elseif($file == '.') {
            //do nothing
        }
        elseif(is_dir($cwd.'/'.$file)) {
            echo '<td><a href=" '.$_SERVER['PHP_SELF'].'?dir='.$cwd.'/'.$file.' ">'.$cwd.'/'.$file.'</a></td>';
            echo '<td><p>'.posix_getpwuid(fileowner($cwd.'/'.$file))["name"].'</p></td>';
            echo '<td><p>'.substr(sprintf('%o', fileperms($cwd.'/'.$file)), -3).'</p></td>';
        }
        else {
            echo '<td><a href=" '.$_SERVER['PHP_SELF'].'?edi='.$cwd.'/'.$file.' ">'.$file.'</a></td>';
            echo '<td><p>'.posix_getpwuid(fileowner($cwd.'/'.$file))["name"].'</p></td>';
            echo '<td><p>'.substr(sprintf('%o', fileperms($cwd.'/'.$file)), -3).'</p></td>';
        }
        echo '<tr>';
    }
echo '</tbody></table>';
echo'
名字

所有者

许可

'; $cwd=getcwd(); 如果(isset($\u GET['dir'])){ $cwd=$_GET['dir']; } $fil=斯堪的纳维亚($cwd); foreach($fil作为$file){ $path=realpath($file); $dir='/'.$file; 回声'; 如果($file==“…”){ $parent=dirname($cwd); 回声'; echo“”.posix_getpwuid(fileowner($file))[“name”]。

; echo“”.substr(sprintf('%o',fileperms($file)),-3)。“

”; } elseif($file='.')){ //无所事事 } elseif(is_dir($cwd./'.$file)){ 回声'; echo“”.posix_getpwuid(fileowner($cwd./'.$file))[“name”]。

”; 回显''.substr(sprintf('%o',fileperms($cwd./'.$file)),-3)。'

'; } 否则{ 回声'; echo“”.posix_getpwuid(fileowner($cwd./'.$file))[“name”]。

”; 回显''.substr(sprintf('%o',fileperms($cwd./'.$file)),-3)。'

'; } 回声'; } 回声';

当然,你需要确保你有一个权限系统,这样只有你才能访问这个页面。如果你想要一个这样的例子,请告诉我。

我一直想把这类东西添加到我的网站编辑功能中。我很高兴你帮我开始了。按计划进行以下工作:

echo '
<table width=50%>
    <thead>
        <tr>
            <th width=60%><p>Name</p></th>
            <th width=20%><p>Owner</p></th>
            <th width=20%><p>Permission</p></th>
        </tr>
    </thead>
    <tbody>
';

    $cwd = getcwd();

    if(isset($_GET['dir'])) {
        $cwd = $_GET['dir'];
    }

    $fil = scandir($cwd);

    foreach ($fil as $file) {
        $path = realpath($file);
        $dir = '/'.$file;
        echo '<tr>';
        if($file == '..'){
            $parent = dirname($cwd);
            echo '<td><a href=" '.$_SERVER['PHP_SELF'].'?dir='.$parent.' ">'.$file.'</a></td>';
            echo '<td><p>'.posix_getpwuid(fileowner($file))["name"].'</p></td>';
            echo '<td><p>'.substr(sprintf('%o', fileperms($file)), -3).'</p></td>';
        }
        elseif($file == '.') {
            //do nothing
        }
        elseif(is_dir($cwd.'/'.$file)) {
            echo '<td><a href=" '.$_SERVER['PHP_SELF'].'?dir='.$cwd.'/'.$file.' ">'.$cwd.'/'.$file.'</a></td>';
            echo '<td><p>'.posix_getpwuid(fileowner($cwd.'/'.$file))["name"].'</p></td>';
            echo '<td><p>'.substr(sprintf('%o', fileperms($cwd.'/'.$file)), -3).'</p></td>';
        }
        else {
            echo '<td><a href=" '.$_SERVER['PHP_SELF'].'?edi='.$cwd.'/'.$file.' ">'.$file.'</a></td>';
            echo '<td><p>'.posix_getpwuid(fileowner($cwd.'/'.$file))["name"].'</p></td>';
            echo '<td><p>'.substr(sprintf('%o', fileperms($cwd.'/'.$file)), -3).'</p></td>';
        }
        echo '<tr>';
    }
echo '</tbody></table>';
echo'
名字

所有者

许可

'; $cwd=getcwd(); 如果(isset($\u GET['dir'])){ $cwd=$_GET['dir']; } $fil=斯堪的纳维亚($cwd); foreach($fil作为$file){ $path=realpath($file); $dir='/'.$file; 回声'; 如果($file==“…”){ $parent=dirname($cwd); 回声'; echo“”.posix_getpwuid(fileowner($file))[“name”]。

; echo“”.substr(sprintf('%o',fileperms($file)),-3)。“

”; } elseif($file='.')){ //无所事事 } elseif(is_dir($cwd./'.$file)){ 回声'; echo“”.posix_getpwuid(fileowner($cwd./'.$file))[“name”]。

”; 回显''.substr(sprintf('%o',fileperms($cwd./'.$file)),-3)。'

'; } 否则{ 回声'; echo“”.posix_getpwuid(fileowner($cwd./'.$file))[“name”]。

”; 回显''.substr(sprintf('%o',fileperms($cwd./'.$file)),-3)。'

'; } 回声'; } 回声';

当然,你需要确保你有一个权限系统,这样只有你才能访问这个页面。如果您想要一个这样的示例,请告诉我。

Apache用户可能没有读取父目录的权限。您需要确保Apache使用的用户具有目录读取和执行权限。Apache用户通常是www-data。Apache用户可能没有读取父目录的权限。您需要确保Apache使用的用户具有目录读取和执行权限。Apache用户通常是www-data。非常感谢。很好,非常感谢。这是炒锅。