better-staridc-MNBT
1<?php
2include("../MPHX/common.php");
3@header('Content-Type: text/html; charset=UTF-8');
4$egn=$_GET['gn'];
5if($islogin==1){}else exit('{"code":"请登陆"}');
6?>
7
8<?php
9$ifsz=$_GET['idh'];
10if(isset($ifsz)){
11$res=$DB->get_row_prepare("SELECT * FROM MN_bs WHERE id=? limit 1", [$ifsz]);
12$file=$res['cxwz'];//需要下载的文件
13$file = iconv("utf-8","gbk//IGNORE",$file);
14if(!file_exists($file)){//判断文件是否存在
15 echo "文件不存在";
16 exit();
17}
18
19$file_name=$res['name'].'.zip';
20$file_name = iconv("utf-8","gbk//IGNORE",$file_name);
21$file_size=filesize("$file");
22ob_clean();
23flush();
24header("Content-Description: File Transfer");
25header("Content-Type:application/force-download");
26header("Content-Length: {$file_size}");
27header("Content-Disposition:attachment; filename={$file_name}");
28readfile("$file");
29exit;
30}elseif($egn=='cxfile'){
31$file='../filecx/export_file.zip';//需要下载的文件
32$file = iconv("utf-8","gbk//IGNORE",$file);
33if(!file_exists($file)){//判断文件是否存在
34 echo "导出的打包文件不存在!您可以重新导出!";
35 exit();
36}
37$file_name='export_file'.mt_rand(10,100).'.zip';
38$file_name= iconv("utf-8","gbk//IGNORE",$file_name);
39$file_size=filesize("$file");
40ob_clean();
41flush();
42header("Content-Description: File Transfer");
43header("Content-Type:application/force-download");
44header("Content-Length: {$file_size}");
45header("Content-Disposition:attachment; filename={$file_name}");
46readfile("$file");
47//@unlink($file);
48exit;
49}
50?>
51
52
53<?php
54if($_GET['ne']=='sw'){
55$file_name='mnbt_swapidc.zip';
56$file="./mnbt/mnbt.sw.zip";//需要下载的文件
57}else{
58// 魔方对接插件下载:优先从源码目录动态打包(mnbthost 虚拟主机 + mnbtdocker Docker),
59// 保证下载到的始终是当前版本;ZipArchive 不可用或打包失败时回退旧静态包
60$file_name='mnbt_mofang.zip';
61$zip_path='../filecx/mnbt_mofang.zip';
62$build_ok=false;
63if(class_exists('ZipArchive')){
64 $zip=new ZipArchive();
65 if($zip->open($zip_path, ZipArchive::CREATE | ZipArchive::OVERWRITE)===true){
66 $src_dirs=['mnbthost'=>'../mf_modules/servers/mnbthost','mnbtdocker'=>'../mf_modules/servers/mnbtdocker'];
67 $has_file=false;
68 foreach($src_dirs as $top=>$dir){
69 if(!is_dir($dir))continue;
70 $files=new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS));
71 foreach($files as $f){
72 if(!$f->isFile())continue;
73 $zip->addFile($f->getPathname(), $top.'/'.substr($f->getPathname(), strlen($dir)+1));
74 $has_file=true;
75 }
76 }
77 $build_ok=$has_file && $zip->close();
78 }
79}
80if($build_ok && file_exists($zip_path)){
81 $file=$zip_path;
82 $file_name='mnbt_mofang.zip';
83}else{
84 $file="./mnbt/mnbt.mr.zip";//需要下载的文件(旧静态包兜底)
85}
86}
87$file = iconv("utf-8","gbk//IGNORE",$file);
88if(!file_exists($file)){//判断文件是否存在
89 echo "文件不存在";
90 exit();
91}
92
93$file_size=filesize("$file");
94ob_clean();
95flush();
96header("Content-Description: File Transfer");
97header("Content-Type:application/force-download");
98header("Content-Length: {$file_size}");
99header("Content-Disposition:attachment; filename={$file_name}");
100readfile("$file");
101exit;
102?>