Ai
1 Star 1 Fork 0

doctor/php遍历文件夹,并列出文件夹下面文件的链接地址

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bianli.php 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
doctor 提交于 2019-03-21 14:56 +08:00 . edit variable name
<?php
@doctor 2019.3.21
//遍历文件夹,获取地址
function getDir($path)
{
//判断目录是否为空
if(!file_exists($path)) {
return [];
}
$files = scandir($path);//目录中的文件和目录
$fileItem = [];
foreach($files as $v) {
$newPath = $path .DIRECTORY_SEPARATOR . $v;
if(is_dir($newPath) && $v != '.' && $v != '..') {//is_dir() 函数检查指定的文件是否是一个目录
$fileItem = array_merge($fileItem, getDir($newPath));//两个数组合并为一个数组
}else if(is_file($newPath)){
$filetype=substr($newPath, strrpos($newPath, '.')+1);//获取文件后缀名
//echo $filetype."|<br/>";
if($filetype=="html"){
$fileItem[] = $newPath;
}
}
}
return $fileItem;
}
echo('action<br/>');
$path = realpath('.');
$files_array=getDir($path);
$fileAddress="lianljie.html";
foreach($files_array as $key=>$val){
$html=$key.".".$val."<hr/><br/>";
file_put_contents($fileAddress, $html, FILE_APPEND | LOCK_EX);
}
echo('end');
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/qruansoft_admin/phpbianli.git
git@gitee.com:qruansoft_admin/phpbianli.git
qruansoft_admin
phpbianli
php遍历文件夹,并列出文件夹下面文件的链接地址
master

搜索帮助