包分安卓和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>";
?>