<?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));

amao
34 声望3 粉丝

不学无术的大三狗一只