我制作了以下脚本,以便在用户登录时显示目录中的文件:
<?php
session_start();
require_once("path/file.php");
if (!empty($_SESSION[username]))
{echo "You <b>$_SESSION[username]</b> are registered.";
$dirPath = dir('includes/path/');
$docArray = array();
while (($file = $dirPath->read()) !== false)
{
if ((substr($file, -3)=="pdf") || (substr($file, -3)=="doc"))
{
$docArray[ ] = trim($file);
}
}
$dirPath->close();
sort($docArray);
$c = count($docArray);
foreach($docArray as $filename)
{
echo "<div><a href=\"./includes/path/$filename\">Download '$filename'</a></div>";
echo "<br/>";
}
include('logout.php');
}
else
{echo "somethingsomething";
include('login.php');
}
?>
在成员表中有两列 MSV 和 LTP,可能的值为 0、1。此外,我还必须目录/path/LTP 和/path/MSV。
我需要在脚本中添加一个内容,如果用户具有 LTP 或/和 MSV 的权限,则会相应地显示文件。
最佳答案
您需要将 LTP
和 MSV
字段的值存储到 $_SESSION
中,并在您的 php 文件中尝试类似的操作用于读取这些文件夹
读取LTP文件夹
if(!empty($_SESSION[LTP])){
//code to read LTP folder
}else{
//Cannot read LTP folder
}
读取MSV文件夹
if(!empty($_SESSION[MSV])){
//code to read MSV folder
}else{
//Cannot read MSV folder
}
假设0
是拒绝访问,1
是授予读取权限
关于PHP脚本根据用户权限动态显示目录中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18516917/