我想在php中打开一个目录,然后显示下载该文件的链接。
这就是我正在尝试的。
if(is_dir($dir))
{
$op=opendir($dir);
echo"Files in the directiry are<br>";
while(($file=readdir($op))!==false)
{
if(strpos($file,$ext,1))
{
echo "<a href=apps/".$file .">".$file."</a><br>";
}
}
}
这显示下载链接,但只到空间。
PHP函数rawurlencode显然可以提供更好的系统覆盖率。Urlencode实际上在我的本地主机上不起作用。
<?php
$dir = 'apps';
$ext = 'pdf';
if(is_dir($dir))
{
$op=opendir($dir);
echo"Files in the directory are<br>";
while(($file=readdir($op))!==false)
{
if(strpos($file,$ext,1))
{
echo '<a href="apps/' . rawurlencode($file) . '">' . $file . '</a><br>';
}
}
}
?>
更多的主题在这里:urlencode vs rawurlencode?