加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 在目录中查找文件

发布时间:2020-12-13 22:14:13 所属栏目:PHP教程 来源:网络整理
导读:我有一个包含很多文件的目录: pic_1_79879879879879879.jpgpic_1_89798798789798789.jpgpic_1_45646545646545646.jpgpic_2_12345678213145646.jpgpic_3_78974565646465645.jpgetc... 我只需要列出pic_1_文件.知道我怎么办? 提前致谢. 解决方法 opend dir函
我有一个包含很多文件的目录:

pic_1_79879879879879879.jpg
pic_1_89798798789798789.jpg
pic_1_45646545646545646.jpg
pic_2_12345678213145646.jpg
pic_3_78974565646465645.jpg
etc...

我只需要列出pic_1_文件.知道我怎么办?
提前致谢.

解决方法

opend dir函数可以帮到你

$dir ="your path here";

$filetoread ="pic_1_";
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
               if (strpos($file,$filetoread) !== false)
                echo "filename: $file : filetype: " . filetype($dir . $file) . "n";
            }
            closedir($dh);
        }
    }

祝你好运看php.net opendir

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读