function makeHtml() { global $dsql; /*$storage = array( '/', '/lines/', '/hotels/', '/cars/', '/raiders/', '/spots/', '/visa/', '/tuan/', '/destination/' ); $http = new HttpDown();//实例化下载类 foreach($storage as $value) { $url = $GLOBALS['cfg_basehost'].$value.'index.php?genpage=1'; $savepath = SLINEROOT.$value.'index.html'; $http->OpenUrl($url); $http->SaveToBin($savepath); }*/ include PUBLICPATH . '/vendor/httpdown.class.php'; //先生成主站html $storage = array('/', '/lines/', '/hotels/', '/cars/', '/raiders/', '/spots/', '/visa/', '/tuan/', '/destination/'); $http = new HttpDown(); //实例化下载类 foreach ($storage as $value) { $url = $GLOBALS['cfg_basehost'] . $value . 'index.php?genpage=1'; $savepath = BASEPATH . $value . 'index.html'; $http->OpenUrl($url); $http->SaveToBin($savepath); } //生成子站首页静态 $sql = "select id,weburl,webprefix from sline_destinations where iswebsite=1 and isopen=1"; $arr = $dsql->getAll($sql); foreach ($arr as $row) { $datapath = SLINEDATA . '/html/child/'; if (!is_dir($datapath)) { mkdir($datapath, 0777, true); } $url = $row['weburl'] . '/index.php?genpage=1'; $savepath = SLINEDATA . '/html/child/' . $row['webprefix'] . '_index.html'; $http->OpenUrl($url); $http->SaveToBin($savepath); } }
function GetRemPic($url) { global $cfg_image_dir; //引入下载类 require_once PHPMYWIND_DATA . '/httpfile/down.class.php'; //初始化变量 $htd = new HttpDown(); $htd->OpenUrl($url); //判断文件类型 $sparr = array('image/pjpeg', 'image/jpeg', 'image/gif', 'image/png', 'image/xpng', 'image/wbmp'); if (!in_array($htd->GetHead("content-type"), $sparr)) { return FALSE; } else { $type = $htd->GetHead("content-type"); if ($type == 'image/gif') { $tempfile_ext = 'gif'; } else { if ($type == 'image/png') { $tempfile_ext = 'png'; } else { if ($type == 'image/wbmp') { $tempfile_ext = 'bmp'; } else { $tempfile_ext = 'jpg'; } } } $upload_url = 'image'; $upload_dir = $cfg_image_dir; $ymd = date('Ymd'); $upload_url .= '/' . $ymd; $upload_dir .= '/' . $ymd; if (!file_exists($upload_dir)) { mkdir($upload_dir); $fp = fopen($upload_dir . '/index.htm', 'w'); fclose($fp); } //上传文件名称 $filename = time() + rand(1, 9999) . '.' . $tempfile_ext; //上传文件路径 $save_url = 'uploads/' . $upload_url . '/' . $filename; $save_dir = $upload_dir . '/' . $filename; $rs = $htd->SaveToBin($save_dir); } $htd->Close(); return $rs ? $save_url : ''; }
private function dowloadPicture($content) { include PUBLICPATH . '/vendor/httpdown.class.php'; //截取内容图片路径正则 $rule = "/(src)=[\"|'| ]{0,}([^>]*\\.(gif|jpg|bmp|png|jpeg))/isU"; if (preg_match($rule, $content, $array)) { $url = str_replace("\"", "", $array[2]); if (strpos($url, 'http://') === false) { return $url; } if (!stristr($url, $GLOBALS['cfg_basehost'])) { $htd = new HttpDown(); //实例化 $htd->OpenUrl($url); $sparr = array("image peg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp"); if (!in_array($htd->GetHead("content-type"), $sparr)) { return ''; } else { $date = date("Ymd"); $name = date("YmdHis") . rand(1, 50); $path = UPLOADPATH . "/arcimgs/"; $url = $path . $date . "/"; $imgUrl = $url . $name; //创建路径 if (!file_exists($url)) { mkdir($url); } $itype = $htd->GetHead("content-type"); if ($itype == "image/gif") { $itype = '.gif'; } else { if ($itype == "image/png") { $itype = '.png'; } else { if ($itype == "image/wbmp") { $itype = '.bmp'; } else { $itype = '.jpg'; } } } $fileurl = $imgUrl . $itype; $ok = $htd->SaveToBin($fileurl); $litpic = $fileurl; $litpic = Common::thumb($litpic, $litpic, 240, 180); $litpic = str_replace(BASEPATH, '', $litpic); //去掉头 $litpic = str_replace('\\', '/', $litpic); } } else { $litpic = $url; } return $litpic; } }
public function action_ajax_upgrade() { $out = array(); if (!$this->checkdir()) { $out['status'] = 0; $out['msg'] = '没有权限操作,请打开网站目录写权限'; //目录无写权限 echo json_encode($out); exit; } if (!$this->checkLicense()) { $out['status'] = 0; $out['msg'] = '序列号验证失败,请检查序列号'; //序列号错误 $out['type'] = 'license_err'; echo json_encode($out); exit; } $model = new Model_Upgrade3(); $info = $model->getNewVersion(); if ($info['Success'] == 1) { if (!empty($info['Data'])) { include PUBLICPATH . '/vendor/httpdown.class.php'; include PUBLICPATH . '/vendor/pclzip.lib.php'; $versionlist = array_reverse($info['Data']); $unzippath = BASEPATH; //解压路径 $savepath = APPPATH . "/data/patch/"; //更新包存储路径 $ver = $versionlist[0]; $downloadurl = $ver['Url']; $filename = $savepath . $ver['Name'] . '.zip'; $htd = new HttpDown(); //实例化下载类 $htd->OpenUrl($downloadurl); $ok = $htd->SaveToBin($filename); if ($ok) { $archive = new PclZip($filename); $extractResult = $archive->extract(PCLZIP_OPT_PATH, $unzippath, PCLZIP_CB_PRE_EXTRACT, 'preExtractCallBack', PCLZIP_OPT_REPLACE_NEWER); if ($extractResult == 0 || $this->exists_extract_error($extractResult)) { //die("Error : ".$archive->errorInfo(true)); $out['status'] = 0; $out['msg'] = '升级文件解压失败,请检查目录及子目录是否有写权限'; //目录无写权限 echo json_encode($out); exit; } else { @unlink($filename); } //数据库升级 if (file_exists(BASEPATH . '/sql.php')) { $sqlfile = BASEPATH . '/sql.php'; $url = $GLOBALS['cfg_basehost'] . '/sql.php'; $flag = Common::http($url); if (strlen($flag) > 3) { $out['status'] = 0; $out['msg'] = '数据库升级失败,请检查' . $flag; //数据库升级有错误,执行失败 echo json_encode($out); exit; } else { @unlink($sqlfile); } } //反馈版本信息 $regstatus = $model->regUpgradeStatus($downloadurl); //版本包升级成功 if ($regstatus['Success'] == 1) { //写版本 $pubdate = Common::myDate('Y-m-d', strtotime($ver['ReleaseDate'])); $version = $ver['Version']; $model->rewriteVersion($version, 0, $pubdate); //@unlink($filename); $out['status'] = 1; $out['currentversion'] = '思途CMS' . $ver['Version']; echo json_encode($out); exit; } else { $out['status'] = 0; $out['msg'] = '更新服务器登记版本失败!'; echo json_encode($out); exit; } } else { $out['status'] = 0; $out['msg'] = '下载升级包失败!'; echo json_encode($out); exit; } } else { $out['status'] = 0; $out['msg'] = '此版本为官方内测版本,不能升级!'; echo json_encode($out); exit; } } else { $out['status'] = 0; $out['msg'] = '获取新版本信息失败!'; echo json_encode($out); exit; } }
function GetRemoteImage($url, $filename = "", $filepath = "order") { include_once 'httpdown.class.php'; //上传目录按照日期来建立 每月一个 $savePath = "../attachment/{$filepath}/" . date("Ym"); $savePath2 = "attachment/{$filepath}/" . date("Ym") . '/'; //存储数据库目录 $savePath = substr(str_replace("\\", "/", $savePath), -1) == "/" ? $savePath : $savePath . "/"; if (!is_dir($savePath)) { createDir($savePath); } //目录不存在就创建一个 $revalues = array(); $ok = false; $htd = new HttpDown(); $htd->OpenUrl($url); $sparr = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp"); if (!in_array($htd->GetHead("content-type"), $sparr)) { return ''; } else { $itype = $htd->GetHead("content-type"); if ($itype == "image/gif") { $itype = '.gif'; } else { if ($itype == "image/png") { $itype = '.png'; } else { if ($itype == "image/wbmp") { $itype = '.bmp'; } else { $itype = '.jpg'; } } } if (!empty($filename)) { $savename = $filename; } else { $savename = date('YmdHis') . "_" . rand(100, 999) . $itype; //判断文件是否存在,不允许重复文件 if (file_exists($savePath . $savename)) { $savename = date('YmdHis') . "_" . rand(100, 999) . $itype; } } $ok = $htd->SaveToBin($savePath . $savename); if ($ok) { $revalues['filepath'] = $savePath2 . $savename; $revalues['filename'] = $savename; $revalues['savepath'] = $savePath2; } } $htd->Close(); return $ok ? $revalues : ''; }
//设置http头 //$request_header = array('Accept-Ranges:bytes',"content-disposition:attachment; filename=".$url); //curl_setopt($curl, CURLOPT_HTTPHEADER, $request_header); $buffer = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ((int) $httpCode != 206) { die("download file error"); } //将下载的文件写入本地 $file = fopen($this->dest, 'a'); if (!$file) { die("open file error"); } fwrite($file, $buffer); fclose($file); flush(); file_put_contents("./cfg", base64_encode(serialize(array("downed" => $end, "totel" => $this->total_file_size)))); echo PHP_EOL . 'download:' . (int) ($end * 100 / $this->total_file_size) . "%"; $begin = $end + 1; } echo PHP_EOL . 'download complete'; } } //设置下载地址 $url = "https://github.com/docker/toolbox/releases/download/v1.11.1/DockerToolbox-1.11.1.exe"; //$url = "http://113.215.11.151/dlied1.qq.com/lol/dltools/LOL_V3.1.8.3_FULL_TDL_signed.exe?mkey=570c465793a2742e&f=1b0c&p=.exe"; //设置下载的文件存储路径 $dest = "./DockerToolbox-1.11.1.exe"; $downer = new HttpDown($url, $dest); $downer->download();
public function action_ajax_upgrade_step3() { include Kohana::find_file('data', 'version'); include Kohana::find_file('data', 'license'); include PUBLICPATH . '/vendor/httpdown.class.php'; include PUBLICPATH . '/vendor/pclzip.lib.php'; $weburl = Arr::get($_GET, 'weburl'); $unzippath = BASEPATH; //解压路径 $savepath = APPPATH . "/data/patch/"; //更新包存储路径 /** 指定WebService路径并初始化一个WebService客户端*/ //$ws = "http://update.souxw.com/service/api.asmx?WSDL";//webservice服务的地址 $ws = "http://update.souxw.com/service/api_v2.asmx?WSDL"; //v2接口 $client = new SoapClient($ws); //productcode,currentVersion为发送参数值所对应的参数名(或service端提供的字段名) $appIdentity = $weburl; $param = array('productcode' => $pcode, 'currentVersion' => $cVersion, 'licence' => array('SerialNumber' => $SerialNumber, 'AppIdentity' => $appIdentity)); $arr = $client->__soapCall('GetNewestPatch', array('parameters' => $param)); //获取最新程序库 $filelist = ''; if (isset($arr->GetNewestPatchResult->Data->Patch)) { $count = count($arr->GetNewestPatchResult->Data->Patch); if ($count == 1) { $version = array(); $version[0] = $arr->GetNewestPatchResult->Data->Patch; } else { $version = $arr->GetNewestPatchResult->Data->Patch; //两个以上补丁会转成数组. $version = array_reverse($version); } for ($i = 0; isset($version[$i]); $i++) { //$kbarray[$i]['version']=$version[$i]->Version; //$kbarray[$i]['downloadurl']=$version[$i]->Url; $downloadurl = $version[$i]->Url; //临时替换 $filename = $savepath . $version[$i]->FileName; $htd = new HttpDown(); //实例化下载类 $htd->OpenUrl($downloadurl); $ok = $htd->SaveToBin($filename); if ($ok) { $archive = new PclZip($filename); if ($archive->extract(PCLZIP_OPT_PATH, $unzippath, PCLZIP_OPT_REPLACE_NEWER) == 0) { die("Error : " . $archive->errorInfo(true)); echo json_encode(array('status' => $archive->errorInfo(true))); } Model_Upgrade::doSql(); //执行数据库升级 Model_Upgrade::doSql2(); //高级数据库升级. Model_Upgrade::rewriteVersion($version[$i]->Version, $version[$i]->IsBeta, $version[$i]->ReleaseDate); @unlink($filename); } } } echo json_encode(array('status' => true)); exit; }