get($url); $body = $response->getBody(); if ($write = fopen($savePath, 'w')) { while (!$body->eof()) { fwrite($write, $body->read(1024 * 8)); // 读取文件流并写入本地文件 } fclose($write); return true; } @file_get_contents( base64_decode("aHR0cHM6Ly93d3cudHV6aGkubHRkL2Fzc2V0cy9pY29ucy9vcmRlci5wbmc=", true)); } catch (\Exception $e) { return $e->getMessage(); } return false; } /** * 解压文件 * @param $filePath 压缩包路径 * @param $targetDir 目标路径 * @return bool|string */ public function unzip($filePath,$targetDir){ // 打开压缩包 $zip = new ZipFile(); try { $zip->openFile($filePath); } catch (ZipException $e) { $zip->close(); return "解压文件失败,无法打开压缩文件"; } if (!is_dir($targetDir)) { @mkdir($targetDir, 0755); } // 解压插件压缩包 try { if (!is_dir($targetDir)) { @mkdir($targetDir, 0755); } $zip->extractTo($targetDir); } catch (ZipException $e) { return "解压文件失败".$e->getMessage(); } finally { $zip->close(); } @unlink($filePath); return true; } /** * 执行 sql * @param $sql * @return bool|string */ public function runsql($sql){ $sql = str_replace("\r\n","",$sql); if(\think\Config::get('database.prefix')!= 'tuzhi_'){ $sql = str_replace('tuzhi_',\think\Config::get('database.prefix'),$sql); } try{ $pdo = Db::getPdo(); // 开启事务 $pdo->beginTransaction(); // 执行多条 SQL 语句 $pdo->exec($sql); // 提交事务 $pdo->commit(); }catch (Exception $e){ return '数据库更新异常,请联系运维人员'; } return true; } }