<?php
Include_once ('./public/update/class-pclzip.php ');
Header (' Content-type:text/json ');
Error_reporting (e_all^e_notice^e_warning);
if ($_get[' a ']== ' start ') {
Link database to determine if it has exceeded the authorization period
$conn =mysql_connect (' 127.0.0.1 ', ' xxx ', ' wxaxxxdmin ');
mysql_query ("Set names ' UTF8 '");
mysql_select_db (' wxadmin ');
$sql = "SELECT * from ims_domains where ' domain ' = '". $_get[' server ']. "' and ' is_domain ' = ' 1 ' limit 1 ";
$result = mysql_query ($sql, $conn);
while ($rs = Mysql_fetch_array ($result)) {
if (Strtotime ($rs [' End_time ')] < time ()) {
$info = Array (
' Status ' = ' 0 ',
' Info ' = ' Your authorization time has expired, please contact QQ1129282710 Recharge '
);
}else{
Header ("Content-type:text/html;charset=utf-8");
$filename = ' http://xxx.cn/Update/fjyedhlcbn/'. $_get[' url ']. Zip ';
$file = GetImage ($filename, ' ', $_get[' url '). Zip ', 1);
Start upgrade
if ($file) {
$filezip = $_get[' url ']. Zip ';
if (file_exists ($filezip)) {
Start unpacking
$zip = new Pclzip ($filezip);
if (! ( $list = $zip->listcontent ())) {
$info = Array (
' Status ' = ' 1 ',
' info ' = ' = ' Get upgrade package content List failed: '. $zip->errorinfo (True)
);
}else{
$zip->extract (Pclzip_opt_path, './',
Pclzip_opt_replace_newer);
Start Database Upgrade
$updatefile = ' Update.sql ';
$sql = file_get_contents ($updatefile);
if ($sql) {
$sql = $sql;
foreach (Split ("; [ \r\n]+ ", $sql) as $v) {
@mysql_query ($v);
}
@unlink ($updatefile);
}
$info = Array (
' Status ' = ' 1 ',
' Info ' + ' Upgrade is successful, please refresh to see if there is an upgrade package '
);
@unlink ($filezip);
}
}else{
$info = Array (
' Status ' = ' 0 ',
' Info ' = ' No upgrade package found '
);
}
}else{
$info = Array (
' Status ' = ' 0 ',
' Info ' = ' Download Failed '
);
}
}
}
Mysql_close ($con);
echo Json_encode ($info);
}
if ($_get[' a '] = = ' Check ') {
echo json_encode (' 20150821 ');
}
if ($_get[' a '] = = ' Update ') {
if ($_get[' V ']) {
Switch ($_get[' V ']) {
Case ($_get[' V '] < ' 20150816 '):
$arr = Array (
' Banben ' = ' 20150817 ',
' url ' = ' http://xxx.com/Update/fjyedhlcbn/20150817.zip ',
' Content ' = ' 1. Initialize online updates. <br>
‘
);
echo Json_encode ($arr);
Break
Case ' 20150818 ':
$arr = Array (
' Banben ' = ' 20150820 ',
' url ' = ' 20150820 ',
' Content ' = ' 1. First online update test <br/>
‘
);
echo Json_encode ($arr);
Break
Case ' 20150820 ':
$arr = Array (
' Banben ' = ' 20150821 ',
' url ' = ' 20150821 ',
' Content ' + ' 1. Second online, two times online, two times online, two times online more than two times Online update testing <br/>
2.22nd Online Shepherds Online Update test <br/>
3. Second two-time online update test <br/>
4. Second two times online more than two times online more than two online update test <br/>
5. Second Online update test <br/>
6. Second two times online more than two times online more than two online update test <br/>
7. Second two times online more than two times online more than two online update test <br/>
8. Second two times online more than two times online more than two online update test <br/>
9. Second two times online more than two times online more than two online update test <br/>
10. Second two times online more than two times online more than two online update test <br/>
‘
);
echo Json_encode ($arr);
Break
}
}
}
/*
* Function: PHP perfect implementation download remote picture saved to local
* Parameters: File URL, save file directory, save file name, use the download method
* Use the original name of the remote file when the save file name is empty
*/
function GetImage ($url, $save _dir= ", $filename =", $type =0) {
if (Trim ($url) = = ") {
Return Array (' file_name ' = ' = ', ' save_path ' = ' = ', ' ERROR ' =>1);
}
if (Trim ($save _dir) = = ") {
$save _dir= './';
}
if (Trim ($filename) = = ") {//Save file name
$ext =strrchr ($url, '. ');
if ($ext! = '. gif ' && $ext! = '. jpg ') {
Return Array (' file_name ' = ' = ', ' save_path ' = ' = ', ' ERROR ' =>3);
}
$filename =time (). $ext;
}
if (0!==strrpos ($save _dir, '/')) {
$save _dir.= '/';
}
Create a Save directory
if (!file_exists ($save _dir) &&!mkdir ($save _dir,0777,true)) {
Return Array (' file_name ' = ' = ', ' save_path ' = ' = ', ' ERROR ' =>5);
}
Methods used to get remote files
if ($type) {
$ch =curl_init ();
$timeout = 5;
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, curlopt_returntransfer,1);
curl_setopt ($ch, Curlopt_connecttimeout, $timeout);
$img =curl_exec ($ch);
Curl_close ($ch);
}else{
Ob_start ();
ReadFile ($url);
$img =ob_get_contents ();
Ob_end_clean ();
}
$size =strlen ($IMG);
File size
[Email protected] ($save _dir. $filename, ' a ');
Fwrite ($fp 2, $img);
Fclose ($fp 2);
Unset ($img, $url);
Return Array (' file_name ' = $filename, ' save_path ' = $save _dir. $filename, ' error ' =>0);
}
?>
This article is from the "Flail Blog" blog, please be sure to keep this source http://jhomephper.blog.51cto.com/8558055/1688376
Download the zip update package remotely using the online update core program implemented by Pclzip