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

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

<?php 
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 '<pre>';
$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 "<table border='2' cellpadding='50px'>
<tr>
<td width='20%'>iOS/安卓</td>
<td width='80%'>下载地址</td>
</tr>";
$content = '';
foreach ($data as $val){
    if($val['type'] == 'IOS'){
        $content = $content ."<tr bgcolor='#87cefa'>
            <td width='20%'>".$val['type']."</td>
        
            <td width='80%'><a href=".$val['url']." target='_blank'>".$val['name']." </a></td>
            </tr>";
    }else{
        $content = $content ."<tr bgcolor='#00ffff'>
            <td width='20%'>".$val['type']."</td>
        
            <td width='80%'><a href=".$val['url']." target='_blank'>".$val['name']." </a></td>
            </tr>";
    }
}
echo $content;
echo "</table>";
?>	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值