即时显示我的文件夹目录中的文件。 当我试过这段代码时,它会打开一个新的浏览器,但得到一个错误的404对象没有找到!我在文件夹中有一个jpg图像。我如何查看我的代码文件夹中的图像?能够查看该文件夹,但不能查看该文件夹内的文件。
<?php
$username=$_SESSION['username' ];
if(isset($_GET['directory']))
{
if(strcmp($_GET['directory'],' userFolders/')==0)
{
$dir='userFolders/'.$username. '/';
}
else
{
$dir=$_GET['directory'];
}
$myfolders=scandir($dir);
if(empty($myfolders))
{
echo '<tr><td> <b> Your folder is empty </b></td><td></td><td></td></ tr>';
}
else
{
foreach($myfolders as $folder)
{
echo '<tr>
<td align="left"><a target=_blank href="honey.php?directory=$folder"> $folder</a></td>
<td align="center"> --- </td>
<td align="center"> <input type="image" src="delete.png" width="25" height="25"/></td>
</tr>';
}
$dir_handle = @opendir($dir) or die("Unable to open $dir");
while ($file = readdir($dir_handle))
{
if($file == "." || $file == "..")
continue;
echo '<tr>
<td align="left"><a target="_blank" href="'.$file.'"> ',$file,'</a></td>
<td align="center"> --- </td>
<td align="center"> <input type="image" src="delete.png" width="25" height="25"/></td>
</tr>';
}
closedir($dir_handle);
}
难道是因为''可以链接至'file' $,这仅仅是文件名?你应该在'$ dir'前加上它。 – andrewsi
你正在做'scandir($ _ GET ['directory'])''。除了安全含义之外,究竟是什么'$ _GET ['directory']';你确定你正在尝试阅读你想要阅读的目录吗? – jeroen
所有文件夹都具有完全权限 – IRock