修复数据DB连接问题+一个脚本文件execlaa.php
This commit is contained in:
parent
518a622482
commit
6e3394a681
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use think\Controller;
|
||||
|
||||
class Execlaa extends Controller
|
||||
{
|
||||
public function readexcel()
|
||||
{
|
||||
$rootPath = $_SERVER['DOCUMENT_ROOT'];
|
||||
$publicPath = rtrim($rootPath, '/');
|
||||
$filePath = '/tsf/2302.xls';
|
||||
$directory = '/tsf/2302班'; // 替换为你的图片文件夹路径
|
||||
// Excel文件路径
|
||||
|
||||
$excelPath = $publicPath . $filePath;
|
||||
|
||||
// dump($excelPath);
|
||||
// die;
|
||||
// 读取Excel文件
|
||||
$spreadsheet = IOFactory::load($excelPath);
|
||||
$worksheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
// dump($spreadsheet);
|
||||
// die;
|
||||
// 获取数据
|
||||
$data = [];
|
||||
$highestRow = $worksheet->getHighestRow(); // 获取最高行数
|
||||
$highestColumn = $worksheet->getHighestColumn(); // 获取最高列
|
||||
|
||||
for ($row = 2; $row <= $highestRow; $row++) { // 假设第一行是标题行
|
||||
$rowData = [];
|
||||
for ($col = 'A'; $col <= $highestColumn; $col++) {
|
||||
$rowData[] = $worksheet->getCell($col . $row)->getValue();
|
||||
}
|
||||
$data[] = $rowData;
|
||||
}
|
||||
|
||||
// 处理数据或返回数据
|
||||
// 例如:输出数据到控制台
|
||||
// foreach ($data as $row) {
|
||||
// var_dump($row);
|
||||
// }
|
||||
|
||||
// 或者你可以将数据保存到数据库或进行其他操作
|
||||
|
||||
// ...
|
||||
// dump($data);
|
||||
// die;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$picPath = $publicPath . $directory;
|
||||
|
||||
$tupian_arr = [];
|
||||
// 打开目录
|
||||
if ($handle = opendir($picPath)) {
|
||||
// 遍历目录中的文件和子目录
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
// 跳过当前目录和上级目录
|
||||
if ($file != "." && $file != "..") {
|
||||
// 检查文件扩展名是否为图片格式
|
||||
$extension = pathinfo($file, PATHINFO_EXTENSION);
|
||||
$imageExtensions = array('jpg', 'jpeg', 'png', 'gif', 'bmp'); // 添加你需要的图片格式
|
||||
|
||||
if (in_array(strtolower($extension), $imageExtensions)) {
|
||||
// 输出图片文件名或进行其他处理
|
||||
// echo "找到图片文件: " . $file . "<br>";
|
||||
// 如果你想获取图片完整路径,可以这样做:
|
||||
$fullPath = $picPath . '/' . $file;
|
||||
// echo "图片完整路径: " . $fullPath . "<br>";
|
||||
// dump($fullPath);
|
||||
// dump($file);
|
||||
// dump(pathinfo($file, PATHINFO_FILENAME));
|
||||
// dump('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
|
||||
$tupian_arr[pathinfo($file, PATHINFO_FILENAME)] = $fullPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 关闭目录
|
||||
closedir($handle);
|
||||
} else {
|
||||
echo "无法打开目录 $directory";
|
||||
}
|
||||
|
||||
foreach ($tupian_arr as $key => $value) {
|
||||
for ($i=0; $i < count($data); $i++) {
|
||||
if($data[$i][0] == $key){
|
||||
$this->renameImage($value,$data[$i][4]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// dump($tupian_arr);
|
||||
// dump($tupian_arr[1]);
|
||||
|
||||
|
||||
// return json(['status' => 'success', 'data' => $data]); // 假设你想返回JSON响应
|
||||
}
|
||||
|
||||
|
||||
public function renameImage($filename,$newfn)
|
||||
{
|
||||
// 假设这是你的图片文件的当前路径
|
||||
// $filename = './public/uploads/old_name.jpg';
|
||||
|
||||
// 构建新的文件名(确保它与目录中的其他文件不冲突)
|
||||
$newfn = $newfn.'.jpg';
|
||||
$rootPath = $_SERVER['DOCUMENT_ROOT'];
|
||||
$publicPath = rtrim($rootPath, '/');
|
||||
$newImagePath = $publicPath . '/tsf/demo/'.$newfn;
|
||||
// $newImagePath = './public/uploads/' . $newFileName;
|
||||
|
||||
// dump($filename);
|
||||
// dump($newImagePath);
|
||||
// 使用rename()函数重命名文件
|
||||
if (rename($filename, $newImagePath)) {
|
||||
// 重命名成功,可以进行其他操作,如记录日志、返回成功消息等
|
||||
echo '图片重命名成功!';
|
||||
} else {
|
||||
// 重命名失败,处理错误
|
||||
echo '图片重命名失败,请检查路径和权限!';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -129,14 +129,19 @@ class Base extends Controller{
|
|||
}
|
||||
}
|
||||
|
||||
// 绑定设备
|
||||
public function base_bind_device(){
|
||||
|
||||
}
|
||||
|
||||
public function msg($code,$msg='',$data=[]){
|
||||
return json(['code'=>$code,'msg'=>$msg,'data'=>$data]);
|
||||
}
|
||||
|
||||
|
||||
public function ceshiyong(){
|
||||
$result = Db::query("select * from app_card_data");
|
||||
dump($result);
|
||||
$result2 = Db::table('app_card_data')->select();
|
||||
dump($result2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -18,8 +18,11 @@ class Login extends Base{
|
|||
################################################################个人资料卡################################################################
|
||||
|
||||
// 注册
|
||||
public function register_action($data = ['tel'=>18866668888,'password'=>'ceshi','code'=>'123456']){
|
||||
public function register_action($data = ['tel'=>18866668889,'password'=>'ceshi','code'=>'123456']){
|
||||
|
||||
// dump('123');
|
||||
phpinfo();
|
||||
die;
|
||||
if(count(input()) > 0){
|
||||
$data = input();
|
||||
}
|
||||
|
|
@ -27,6 +30,7 @@ class Login extends Base{
|
|||
if(!is_array($verify_result)){
|
||||
return $this->msg(10001,$verify_result);
|
||||
}
|
||||
// dump('321');
|
||||
// 记录
|
||||
$result = Db::table('app_account_number')->insert($verify_result);
|
||||
if($result){
|
||||
|
|
@ -243,7 +247,7 @@ class Login extends Base{
|
|||
if(!$result){
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
// dump('3211');
|
||||
// 判断参数
|
||||
if(array_key_exists('tel', $data)){
|
||||
$parameter['tel'] = $data['tel'];
|
||||
|
|
@ -257,13 +261,18 @@ class Login extends Base{
|
|||
return '手机/邮箱必须';
|
||||
}
|
||||
|
||||
dump($montage_data);
|
||||
// 检验是否注册过
|
||||
if($montage_data == 'tel'){
|
||||
$inspect_repeat = Db::table('app_account_number')->where(['tel'=>$parameter['tel'],'password'=>$parameter['password']])->count();
|
||||
// $inspect_repeat = Db::table('app_account_number')->where(['tel'=>$parameter['tel'],'password'=>$parameter['password']])->count();
|
||||
$inspect_repeat = Db::query("select count(*) from app_account_number where tel='".$parameter['tel']."'and password='".$parameter['password']);
|
||||
}else{
|
||||
$inspect_repeat = Db::table('app_account_number')->where(['email'=>$parameter['email'],'password'=>$parameter['password']])->count();
|
||||
}
|
||||
|
||||
|
||||
dump($inspect_repeat);
|
||||
// dump('3212');
|
||||
if($inspect_repeat){
|
||||
return '注册失败,账号已存在';
|
||||
}
|
||||
|
|
@ -300,8 +309,9 @@ class Login extends Base{
|
|||
return $str;
|
||||
}
|
||||
|
||||
public function msg($code,$msg='',$data=[]){
|
||||
return json(['code'=>$code,'msg'=>$msg,'data'=>$data]);
|
||||
public function demo_db(){
|
||||
dump('开始测试');
|
||||
$this->ceshiyong();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -94,6 +94,10 @@ Route::any('/vitalcapacity_data_set', 'app/vitalcapacity/vitalcapacity_data_set'
|
|||
// // ################################################################其它测试################################################################
|
||||
Route::any('/generateRandomJumpData', 'app/skip/generateRandomJumpData');
|
||||
Route::any('/setdb', 'app/skip/setdb');
|
||||
Route::any('/readexcel', 'admin/execlaa/readexcel');
|
||||
Route::any('/demo_db', 'app/login/demo_db');
|
||||
|
||||
|
||||
// Route::any('/isNumericArray', 'app/base/isNumericArray');
|
||||
|
||||
// 处理404错误 z
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"topthink/framework": "5.0.*",
|
||||
"phpmailer/phpmailer": "^6.9"
|
||||
"phpmailer/phpmailer": "^6.9",
|
||||
"phpoffice/phpspreadsheet": "^1.25"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue