php - 实际许可和所有者未打印
问题描述
我正在本地服务器上编写 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-data。
请注意:您不想让用户访问他们不应该看到的文件或目录!
您可以使用以下命令更改目录组:
chgrp www-data <directory_name>
推荐阅读
- javascript - jquery 不在 IE、EDGE 和 FIREFOX 中工作,但在 CHROME 中工作
- android - 库升级到 1.1.3 后 ConstraintLayout 崩溃
- php - 如何在没有嵌套foreach循环的情况下基于键值对组合两个多维数组?
- c# - 在 Asp.Net Web Api 的 EntityFramework 中更新之前查找表对象实体以获取列的当前值
- java - 线程“主”java.lang.NoClassDefFoundError 中的异常:org/apache/commons/lang/builder/CompareToBuilder
- android - 如何在ffmpeg中合并音频和两个视频文件?
- java - 如何读取 java 类中的运行时变量?
- python - 关于在循环中添加字符的问题
- python - 新类实例继承以前的实例值
- ios - 在声明一个强自我之后在闭包中使用 [弱自我] 是否有潜在的缺点?