-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload_file.php
More file actions
197 lines (164 loc) · 6.16 KB
/
upload_file.php
File metadata and controls
197 lines (164 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
error_reporting(0);
header('Content-type: text/html; charset=utf-8');
include('conn_mysql.php');
include('DownPlistCreator.php');
?>
<?php
var_dump($_FILES);
function getInfoPlist($ipaFilePath){
$dirPath = dirname($ipaFilePath);
$fileExtension = pathinfo($ipaFilePath, PATHINFO_EXTENSION);
$dirPath = $dirPath.'/'.basename($ipaFilePath,'.'.$fileExtension);
// echo $dirPath;
if (!file_exists($dirPath)) {
mkdir($dirPath);
}
$zip=new ZipArchive();//新建一个ZipArchive的对象
if($zip->open($ipaFilePath)===TRUE){
$zip->extractTo($dirPath);//假设解压缩到在当前路径下images文件夹内
$zip->close();//关闭处理的zip文件
}
$payloadPath = $dirPath."/Payload";
// echo $payloadPath;
// $payloadDir = opendir($payloadPath);
// $copyPath = readdir($payloadDir);
// echo $copyPath;
$infoPlistPath;
if(is_dir($payloadPath))
{
if ($dh = opendir($payloadPath))
{
while (($file = readdir($dh)) !== false)
{
if((is_dir($payloadPath."/".$file)) && $file!="." && $file!="..")
{
// echo "<b><font color='red'>文件名:</font></b>",$file,"<br><hr>";
$infoPlistPath = $payloadPath."/".$file."/Info.plist";
}
else
{
if($file!="." && $file!="..")
{
// echo $file."<br>";
}
}
}
closedir($dh);
}
}
// echo $infoPlistPath;
return $infoPlistPath;
// readInfoPlist($infoPlistPath);
}
function deleteAll($path) {
$op = dir($path);
while(false != ($item = $op->read())) {
if($item == '.' || $item == '..') {
continue;
}
if(is_dir($op->path.'/'.$item)) {
deleteAll($op->path.'/'.$item);
rmdir($op->path.'/'.$item);
} else {
unlink($op->path.'/'.$item);
}
}
rmdir($path);
}
if (!is_uploaded_file($_FILES["upfile"]['tmp_name'])){
echo "无效的文件!";
exit;
}
$app_name1 = $_FILES["upfile"]['name'];
include('conn_mysql.php');
$sql="select distinct app_name from new_app_info where app_name= '$app_name1' and app_status=1 and app_power in (1,2,3) ";
$result1=mysqli_query($conn,$sql);
@ $row = mysqli_fetch_array($result1);
if($app_name1==$row[app_name]){
echo "文件已存在!";
exit;
}
$ar=explode('.',$app_name1);
$lcy=count($ar);
if($_POST[style] ==''){
echo "上传失败!请选择安装平台!";
exit;
}
if($ar[$lcy-1] =="ipa" || $ar[$lcy-1]=="apk"){
}
else{
echo "上传失败!文件类型不正确,请选择正确的文件类型!";
exit;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$ServerUrl=$_SERVER['DOCUMENT_ROOT'];
if($_POST['release']=="1"){
if($ar[$lcy-1] =="ipa")
{
$project_id = $_POST['project'];
$sql="select * from new_config_prj where prj_num = $project_id";
$result1=mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result1)){
$project_name =$row[prj_name];
}
$destination_folder="/new_app/pub_ipa/"; //上传文件路径
$file = $_FILES["upfile"];
$filename=$file["tmp_name"];
$pinfo=pathinfo($file["name"]);
$ftype=$pinfo['basename'];
$destination_folder = $ServerUrl.$destination_folder;
if(!file_exists($destination_folder))
{
mkdir($destination_folder);
}
$destination = $destination_folder.$ftype;
if(!move_uploaded_file ($filename, $destination))
{
echo "移动文件出错!";
exit;
}
$infoPlistPath = getInfoPlist($destination);
$idAndversion = CFPropertyList\DownPlistCreator::readInfoPlist($infoPlistPath);
$fileNameMD5 = md5(basename($destination,".ipa"));
$downPlistPath = '../new_app/pub_plist/'.$fileNameMD5.'.plist';
$downFileIcon = 'https://192.168.1.175/new_app/project_icon/'.$project_name.'.png';
CFPropertyList\DownPlistCreator::createDownPlist('https://192.168.1.175/new_app/pub_ipa/'.basename($destination),$downFileIcon,
$downFileIcon,$downPlistPath,$idAndversion[0],$idAndversion[1]);
$unloadPackgePath = $destination_folder.basename($destination,".ipa");
deleteAll($unloadPackgePath);
}
else{
$destination_folder="/new_app/pub_apk/"; //上传android文件路径
$file = $_FILES["upfile"];
$filename=$file["tmp_name"];
$pinfo=pathinfo($file["name"]);
$ftype=$pinfo['basename'];
$destination_folder = $ServerUrl.$destination_folder;
if(!file_exists($destination_folder))
{
mkdir($destination_folder);
}
$destination = $destination_folder.$ftype;
if(!move_uploaded_file ($filename, $destination))
{
echo "移动文件出错!";
exit;
}
}
}
include('conn_mysql.php');
$app_name = $_FILES["upfile"]['name'];
$sql="insert into new_app_info (project,platform,version,app_name,app_status,app_power,add_time,add_name,add_ip,del_name) values('$_POST[project]','$_POST[style]','','$app_name','1','$_POST[release]',now(),'$_POST[username]','$ipd','')";
// echo $sql;
// exit;
if( $result=mysqli_query($conn,$sql)){
echo "恭喜!您的文件上传成功!";
}
else{
echo "数据插入失败!";
echo $sql;
exit;
}
}
?>