PHP 获取文件夹下文件,返回url

amao
<?php
//设置数据格式-- json
header('content-type:application/json;charset=utf-8');
// *代表允许任何网址请求
header('Access-Control-Allow-Origin:*');
// 允许请求的类型
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE');
// 设置允许自定义请求头的字段
header('Access-Control-Allow-Headers:*');
//屏蔽参数为空警告  
error_reporting(0);



function tree(&$arr_file, $directory, $dir_name = '')
{
    $mydir = dir($directory);
    while ($file = $mydir->read()) {
        if ((is_dir("$directory/$file")) and ($file != ".") and ($file != "..")) {
            tree($arr_file, "$directory/$file", "$dir_name/$file");
        } else if (($file != ".") and ($file != "..")) {
            $ext = strrchr($file, '.');
            //筛选文件格式
            if($ext == '.mp4' || $ext == '.mkv' || $ext == '.avi'){
                //$encoded = urlencode("$dir_name/$file");
                $singel = array(
                'url' => 'http://amaoa.me/download' . "$dir_name/$file",
                'name'=> basename($file, strrchr($file, '.')),
                'type'=> substr(strrchr($file, '.'), 1) 
            );
            array_push($arr_file, $singel);
            }
        }
    }
    $mydir->close();
}

//开始运行
$arr_file = array();
tree($arr_file, "./download");
exit(json_encode($arr_file));
阅读 1.2k

不学无术的大三狗一只

25 声望
2 粉丝
0 条评论

不学无术的大三狗一只

25 声望
2 粉丝
文章目录
宣传栏