当前位置:网站首页 / 建站 / 正文

php遍历指定文件夹并生成下载链接代码

时间:2016年09月09日 | 作者 : liuhui | 分类 : 建站 | 浏览: 8260次 | 评论 1

阿里云限量代金券 | 此广告位出租25元/月

1.jpg

代码如下:

<?php
 
$dir="./upload"; //指定的路径
$sitepath = 'http://localhost/upload/';
//遍历文件夹下所有文件
if (false != ($handle = opendir ( $dir ))) {
    echo "$dir 目录下的文件列表:<br />";
    $i = 0;
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && !is_dir($dir.'/'.$file)) {
            echo '<a href="' . $sitepath . $file . '">'.$file. '</a><br />';
        }
    }
    //关闭句柄
    closedir($handle);
}
 
?>

代码安全提示:如果是运行于互联网上,需要考虑文件的访问安全性。

运行截图:

1.jpg


推荐您阅读更多有关于“”的文章

猜你喜欢

网站分类
关注电脑博士
友情链接

分享:

支付宝

微信