PHP搭建app的apk简单下载管理

包分安卓和iOS包,然后分为两个文件夹,读取俩文件夹下的文件,实现展示和下载功能!

 
function read_all_dir ( $dir ){

    $result = array();
    $handle = opendir($dir);//读资源
    if ($handle){
        while (($file = readdir($handle)) !== false ){
            if ($file != '.' && $file != '..'){
                $cur_path = $dir . DIRECTORY_SEPARATOR . $file;
                if (is_dir($cur_path )){//判断是否为目录,递归读取文件
                    $result['dir'][$cur_path] = read_all_dir($cur_path );
                }else{
                    $result['file'][] = $cur_path;
                }
            }
        }
        closedir($handle);
    }
    return $result;
}
echo '
';
$file =read_all_dir('/www/wwwroot/apk/');
$host = '下载地址';

$data = [];
foreach ($file['dir'] as $key => $val){
    if(strstr($key, 'IOS')){
        if(isset($val['file'])){
            foreach ($val['file'] as $v){
                $data[] = array(
                    'type' => 'IOS',
                    'url' => $host.'IOS/'.str_replace($key, '', $v),
                    'name' => str_replace($key, '', $v)
                );
            }
        }
    }

    if(strstr($key, 'Android')){
        foreach ($val['file'] as $v){
            $data[] = array(
                'type' => 'Android',
                'url' => $host.'Android/'.str_replace($key, '', $v),
                'name' => str_replace($key, '', $v)
            );
        }
    }
}


echo "";$content='';foreach($dataas$val){if($val['type']=='IOS'){$content=$content."";}else{$content=$content."";}}echo$content;echo"
iOS/安卓 下载地址
".$val['type']." .$val['url']." target='_blank'>".$val['name']."
".$val['type']." .$val['url']." target='_blank'>".$val['name']."
"
; ?>

你可能感兴趣的:(PHP)