首页
留言
统计
朋友
关于
推荐
我的动态
Search
1
宝塔安装git,实现实时更新服务器代码
110 阅读
2
hello world!- 我的博客诞生啦~
78 阅读
3
PHP之PhpSpreadsheet 的使用
68 阅读
4
利用数组做积分系统
61 阅读
5
Elasticsearch的学习笔记(一)
53 阅读
工作
学习
生活
登录
/
注册
Search
标签搜索
elasticsearch
PHP
Hello World
PhpSpreadsheet
elasticsearch-php
默然
累计撰写
11
篇文章
累计收到
7
条评论
首页
栏目
工作
学习
生活
页面
留言
统计
朋友
关于
推荐
我的动态
搜索到
8
篇与
的结果
2022-04-07
PHP之PhpSpreadsheet 的使用
今天看了下PhpSpreadsheet 的使用,以前只看过phpExcel相关的,这里的数据全是随机生成的,生成代码在下方,不必要看代码,就一个思路,哈哈哈,大佬绕过!连接数据库(conn.php)<?php $servername = "localhost"; $username = "root"; $password = "123456"; $database = "hotel"; // 创建连接 $conn = mysqli_connect($servername, $username, $password, $database); // 检测连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } //echo "连接成功"; 首页(index.php)<?php require_once "./conn.php"; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>首页</title> <link rel="stylesheet" href="./common/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> </head> <body> <br> <div class="row"> <div class="col-4"></div> <div class="col-4 file-group"> <a href="./exportdown.php" target="_blank" style="color: #fff;;"><button class="btn btn-primary col-4">导出</button></a> <input type="file" style="display: none"> <button class="btn btn-primary col-4 file-browser" id="import">导入</button> </div> <div class="col-4"></div> </div> <br> <div class="container"> <table class="table table-bordered"> <thead> <tr> <th scope="col">序号</th> <th scope="col">账号</th> <th scope="col">姓名</th> <th scope="col">年龄</th> <th scope="col">性别</th> <th scope="col">创建时间</th> </tr> </thead> <tbody> <?php $sql = "select * from test"; $result = mysqli_query($conn,$sql); while ($rows = mysqli_fetch_array($result)) { echo "<tr><th>$rows[0]</th>"; echo "<th>$rows[1]</th>"; echo "<th>$rows[2]</th>"; echo "<th>$rows[3]</th>"; echo "<th>$rows[4]</th>"; echo "<th>$rows[5]</th></tr>"; } ?> </tbody> </table> </div> </body> <script> $(document).ready(function() { $(document).on('click', '.file-browser', function() { console.log(233); var $browser = $(this); var file = $browser.closest('.file-group').find('[type="file"]'); file.on( 'click', function(e) { e.stopPropagation(); }); file.trigger('click'); }); $(document).on('change', '.file-group [type="file"]', function() { var $this = $(this); var $input = $(this)[0]; var $len = $input.files.length; var formFile = new FormData(); if ($len == 0) { return false; } else { var fileAccaccept = $this.attr('accaccept'); var fileType = $input.files[0].type; var type = (fileType.substr(fileType.lastIndexOf("/") + 1)).toLowerCase(); formFile.append("file", $input.files[0]); } var data = formFile; $.ajax({ url: "./upload.php", data: data, type: "POST", dataType: "json", //上传文件无需缓存 cache: false, //用于对data参数进行序列化处理 这里必须false processData: false, //必须 contentType: false, success: function (res) { if(res.code == 200){ alert('导入成功'); } } }); }); }); </script> </html>生成名字(name.php)用了某个大老的 翻不到谁的了 等我再找找 找到补上连接<?php class rndChinaName { private $arrXing, $numbXing; private $arrMing, $numbMing; function rndChinaName() { $this->getXingList(); $this->getMingList(); } /* 获取姓列表 */ private function getXingList() { $this->arrXing = array( '赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈', '褚', '卫', '蒋', '沈', '韩', '杨', '朱', '秦', '尤', '许', '何', '吕', '施', '张', '孔', '曹', '严', '华', '金', '魏', '陶', '姜', '戚', '谢', '邹', '喻', '柏', '水', '窦', '章', '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦', '昌', '马', '苗', '凤', '花', '方', '任', '袁', '柳', '鲍', '史', '唐', '费', '薛', '雷', '贺', '倪', '汤', '滕', '殷', '罗', '毕', '郝', '安', '常', '傅', '卞', '齐', '元', '顾', '孟', '平', '黄', '穆', '萧', '尹', '姚', '邵', '湛', '汪', '祁', '毛', '狄', '米', '伏', '成', '戴', '谈', '宋', '茅', '庞', '熊', '纪', '舒', '屈', '项', '祝', '董', '梁', '杜', '阮', '蓝', '闵', '季', '贾', '路', '娄', '江', '童', '颜', '郭', '梅', '盛', '林', '钟', '徐', '邱', '骆', '高', '夏', '蔡', '田', '樊', '胡', '凌', '霍', '虞', '万', '支', '柯', '管', '卢', '莫', '柯', '房', '裘', '缪', '解', '应', '宗', '丁', '宣', '邓', '单', '杭', '洪', '包', '诸', '左', '石', '崔', '吉', '龚', '程', '嵇', '邢', '裴', '陆', '荣', '翁', '荀', '于', '惠', '甄', '曲', '封', '储', '仲', '伊', '宁', '仇', '甘', '武', '符', '刘', '景', '詹', '龙', '叶', '幸', '司', '黎', '溥', '印', '怀', '蒲', '邰', '从', '索', '赖', '卓', '屠', '池', '乔', '胥', '闻', '莘', '党', '翟', '谭', '贡', '劳', '逄', '姬', '申', '扶', '堵', '冉', '宰', '雍', '桑', '寿', '通', '燕', '浦', '尚', '农', '温', '别', '庄', '晏', '柴', '瞿', '阎', '连', '习', '容', '向', '古', '易', '廖', '庾', '终', '步', '都', '耿', '满', '弘', '匡', '国', '文', '寇', '广', '禄', '阙', '东', '欧', '利', '师', '巩', '聂', '关', '荆', '司马', '上官', '欧阳', '夏侯', '诸葛', '闻人', '东方', '赫连', '皇甫', '尉迟', '公羊', '澹台', '公冶', '宗政', '濮阳', '淳于', '单于', '太叔', '申屠', '公孙', '仲孙', '轩辕', '令狐', '徐离', '宇文', '长孙', '慕容', '司徒', '司空' ); $this->numbXing = count($this->arrXing); //姓总数 } /* 获取名列表 */ private function getMingList() { $this->arrMing = array( '伟', '刚', '勇', '毅', '俊', '峰', '强', '军', '平', '保', '东', '文', '辉', '力', '明', '永', '健', '世', '广', '志', '义', '兴', '良', '海', '山', '仁', '波', '宁', '贵', '福', '生', '龙', '元', '全', '国', '胜', '学', '祥', '才', '发', '武', '新', '利', '清', '飞', '彬', '富', '顺', '信', '子', '杰', '涛', '昌', '成', '康', '星', '光', '天', '达', '安', '岩', '中', '茂', '进', '林', '有', '坚', '和', '彪', '博', '诚', '先', '敬', '震', '振', '壮', '会', '思', '群', '豪', '心', '邦', '承', '乐', '绍', '功', '松', '善', '厚', '庆', '磊', '民', '友', '裕', '河', '哲', '江', '超', '浩', '亮', '政', '谦', '亨', '奇', '固', '之', '轮', '翰', '朗', '伯', '宏', '言', '若', '鸣', '朋', '斌', '梁', '栋', '维', '启', '克', '伦', '翔', '旭', '鹏', '泽', '晨', '辰', '士', '以', '建', '家', '致', '树', '炎', '德', '行', '时', '泰', '盛', '雄', '琛', '钧', '冠', '策', '腾', '楠', '榕', '风', '航', '弘', '秀', '娟', '英', '华', '慧', '巧', '美', '娜', '静', '淑', '惠', '珠', '翠', '雅', '芝', '玉', '萍', '红', '娥', '玲', '芬', '芳', '燕', '彩', '春', '菊', '兰', '凤', '洁', '梅', '琳', '素', '云', '莲', '真', '环', '雪', '荣', '爱', '妹', '霞', '香', '月', '莺', '媛', '艳', '瑞', '凡', '佳', '嘉', '琼', '勤', '珍', '贞', '莉', '桂', '娣', '叶', '璧', '璐', '娅', '琦', '晶', '妍', '茜', '秋', '珊', '莎', '锦', '黛', '青', '倩', '婷', '姣', '婉', '娴', '瑾', '颖', '露', '瑶', '怡', '婵', '雁', '蓓', '纨', '仪', '荷', '丹', '蓉', '眉', '君', '琴', '蕊', '薇', '菁', '梦', '岚', '苑', '婕', '馨', '瑗', '琰', '韵', '融', '园', '艺', '咏', '卿', '聪', '澜', '纯', '毓', '悦', '昭', '冰', '爽', '琬', '茗', '羽', '希', '欣', '飘', '育', '滢', '馥', '筠', '柔', '竹', '霭', '凝', '晓', '欢', '霄', '枫', '芸', '菲', '寒', '伊', '亚', '宜', '可', '姬', '舒', '影', '荔', '枝', '丽', '阳', '妮', '宝', '贝', '初', '程', '梵', '罡', '恒', '鸿', '桦', '骅', '剑', '娇', '纪', '宽', '苛', '灵', '玛', '媚', '琪', '晴', '容', '睿', '烁', '堂', '唯', '威', '韦', '雯', '苇', '萱', '阅', '彦', '宇', '雨', '洋', '忠', '宗', '曼', '紫', '逸', '贤', '蝶', '菡', '绿', '蓝', '儿', '翠', '烟', '小', '轩' ); //名总数 $this->numbMing = count($this->arrMing); } // 获取姓 private function getXing() { // mt_rand() 比rand()方法快四倍,而且生成的随机数比rand()生成的伪随机数无规律。 return $this->arrXing[mt_rand(0, $this->numbXing - 1)]; } // 获取名字 private function getMing() { return $this->arrMing[mt_rand(0, $this->numbMing - 1)]; } // 获取名字 public function getName($type = 0) { $name = ''; switch ($type) { case 1: //2字 $name = $this->getXing() . $this->getMing(); break; case 2: //随机2、3个字 $name = $this->getXing() . $this->getMing(); if (mt_rand(0, 100) > 50) $name .= $this->getMing(); break; case 3: //只取姓 $name = $this->getXing(); break; case 4: //只取名 $name = $this->getMing(); break; case 0: default: //默认情况 1姓+2名 $name = $this->getXing() . $this->getMing() . $this->getMing(); } return $name; } } 添加数据到数据库(while.php) /** * @param $num 数据条数 */ getdata(100); function getdata($num) { require './conn.php'; require 'name.php'; for ($a = 0; $a < $num; $a++) { //随机生成姓名 $name_obj = new rndChinaName(); $nickname = $name_obj->getName(2); //随机输出男女 $my_array = ['男', '女']; $sex = $my_array[rand(0, 1)]; //随机年龄 $age = rand(10, 50); //随机name $characters = 'abcdefghijklmnopqrstuvwxyz'; $name = ''; for ($i = 0; $i < 6; $i++) { $index = rand(0, strlen($characters) - 1); $name .= $characters[$index]; } //添加时间 $creattime = date("Y-m-d H:i:s",time()); $sql = "insert into test(name,nickname,sex,age,creattime) values ('$name','$nickname','$sex','$age','$creattime')"; $res = $conn->query($sql); if (!$res) { echo $a . '添加失败<br>'; } else { echo $a . '添加成功<br>'; } } }导出数据(exportdown.php)<?php require __DIR__.'/conn.php'; $sql = "select * from test"; $result = mysqli_query($conn,$sql); $rows = mysqli_fetch_all($result); # 载入 autoload require_once __DIR__.'/vendor/autoload.php'; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; $spreadsheet=new Spreadsheet(); $sheet=$spreadsheet->getActiveSheet(); //设置标题 $sheet ->setCellValue('A1','ID'); $sheet ->setCellValue('B1','账号'); $sheet ->setCellValue('C1','姓名'); $sheet ->setCellValue('D1','性别'); $sheet ->setCellValue('E1','年龄'); $sheet ->setCellValue('F1','创建时间'); //设置表内数据 $sheet->fromArray( $rows, null, 'A2' ); //MIME 协议,文件的类型,不设置,会默认html header('Content-Type:application/vnd.ms-execl'); //MIME 协议的扩展 header('Content-Disposition:attachment;filename=下载.xls'); //缓存控制 header('Cache-Control:max-age=0'); $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet,'Xlsx'); // php://output 它是一个只写数据流,允许你以 print 和 echo 一样的方式写入到输出缓冲区。 $writer->save('php://output'); 导入数据<?php //print_r($_FILES); $file = $_FILES['file']['tmp_name']; //载入composer自动加载文件 require_once __DIR__.'/vendor/autoload.php'; //载入方法库 require 'conn.php'; //创建读操作 $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); //打开文件、载入execl表格 $spreadsheet = $reader->load($file); //获取活动工作簿 $sheet=$spreadsheet->getActiveSheet(); //获取总列数 $highestColum = $sheet->getHighestColumn(); //获取总行数 $highestRow = $sheet->getHighestRow(); //列数 改为数字显示 $highestColumIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColum); $log =[]; for($a=2;$a<$highestRow;$a++){ $name = $sheet->getCellByColumnAndRow(1,$a)->getValue(); $nickname = $sheet->getCellByColumnAndRow(2,$a)->getValue(); $sex = $sheet->getCellByColumnAndRow(3,$a)->getValue(); $age = $sheet->getCellByColumnAndRow(4,$a)->getValue(); $creattime = date('Y-m-d H:i:s',time()); $add = "insert into test(name,nickname,sex,age,creattime) values ('$name','$nickname','$sex','$age','$creattime')"; $res = $conn->query($add); if($res){ $log[] ='第'.$a.'条插入成功'; }else{ $log[] ='第'.$a.'条插入失败'; } } echo json_encode(['code'=>200,'msg'=>'成功','data'=>array('log'=>$log)]); ?>后缀对应的 content-type表头表头后缀MIME Type.docapplication/msword.dotapplication/msword.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document.dotxapplication/vnd.openxmlformats-officedocument.wordprocessingml.template.docmapplication/vnd.ms-word.document.macroEnabled.12.dotmapplication/vnd.ms-word.template.macroEnabled.12.xlsapplication/vnd.ms-excel.xltapplication/vnd.ms-excel.xlaapplication/vnd.ms-excel.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet.xltxapplication/vnd.openxmlformats-officedocument.spreadsheetml.template.xlsmapplication/vnd.ms-excel.sheet.macroEnabled.12.xltmapplication/vnd.ms-excel.template.macroEnabled.12.xlamapplication/vnd.ms-excel.addin.macroEnabled.12.xlsbapplication/vnd.ms-excel.sheet.binary.macroEnabled.12.pptapplication/vnd.ms-powerpoint.potapplication/vnd.ms-powerpoint.ppsapplication/vnd.ms-powerpoint.ppaapplication/vnd.ms-powerpoint.pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentation.potxapplication/vnd.openxmlformats-officedocument.presentationml.template.ppsxapplication/vnd.openxmlformats-officedocument.presentationml.slideshow.ppamapplication/vnd.ms-powerpoint.addin.macroEnabled.12.pptmapplication/vnd.ms-powerpoint.presentation.macroEnabled.12.potmapplication/vnd.ms-powerpoint.presentation.macroEnabled.12.ppsmapplication/vnd.ms-powerpoint.slideshow.macroEnabled.12
2022年04月07日
68 阅读
2 评论
1 点赞
2022-03-31
宝塔安装git,实现实时更新服务器代码
这几天一直在更新默然iapp后台管理系统,群友们都说弄个在线更新,一直没有思路,后面想到我就是利用git上传的呀,服务端也可以用git呀,然后就有了这篇文章。一、服务端安装gityum install -y git接下来,我们来验证下安装成功没,直接输入git就可以了出现上面这个就是安装成功了这样查看版本号git version配置git信息接下来配置自己的git信息git config --global user.name "your name" git config --global user.email "you email"我们必须创建公钥才能拉去里面的代码ssh-keygen -C "your email" -t rsa一直回车就可以了然后这样查看公钥cat /root/.ssh/id_rsa.pub把公钥复制,配置到gitee上gitee位置:配置完后可以用这个命令测试下:ssh -T git@gitee.com这样就配置完成了,是不是很简单呢,那下面我们来拉代码!git clone https://gitee.com/morannb/moranht.git然后把刚才下载的源码所有文件移动到你的站点目录下,liunx服务器切换目录到站点目录下输入git pull如果gitee端没有任何更新,则向先下面这样有更新的话,则是下图:好了 大功完成了 记住一定不能删除.git文件夹以后直接输入git pull 就完成更新了 记得一定要在有.git那个目录下,但是也有弊端,要重新输入账号密码
2022年03月31日
110 阅读
1 评论
0 点赞
2022-03-29
利用数组做积分系统
今早在写积分系统的时候,开始就想着用着数组来弄,所以数据库字段也就留了一个;当写到这里的时候,就在想怎么利用一个数字去这段数组里面查它的等级名称是啥,开始用判断的比较,后面想了下,我也不知道用户会分几个等级,就以失败告终了!所以最终的代码就变成了这样:public function gettitle($array,$number){ foreach ($array as $key => $value) { if ($number >= $key) { $hierarchy = $value; } else { break; } } } $array = [0 => '名称1',100=>'名称2',200=>'名称3',300=>'名称4',400=>'名称5']; echo gettitle($array,150); //输出为名称2这样就完成了一个数字去数组里判断它属于那个称号!
2022年03月29日
61 阅读
1 评论
1 点赞
1
2