HaniBlindBox/server/php/app/admin/controller/Markdown.php
2026-01-01 20:46:07 +08:00

78 lines
2.1 KiB
PHP

<?php
namespace app\admin\controller;
use think\facade\View;
/**
* Markdown文件查看器
*/
class Markdown extends Base
{
/**
* 显示Markdown文件
*/
public function index()
{
// 获取文件路径参数
$filePath = request()->param('file_path', '');
// 验证文件路径是否有效
if (empty($filePath) || !file_exists($filePath)) {
return $this->err('文件不存在或路径无效');
}
// 检查文件扩展名
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
if (strtolower($extension) !== 'md') {
return $this->err('只支持查看Markdown文件(.md)');
}
// 读取文件内容
$content = file_get_contents($filePath);
// 将内容传递给视图
View::assign('file_path', $filePath);
View::assign('content', $content);
// 返回视图
return View::fetch("Markdown/index");
}
/**
* 显示Markdown文件
*/
public function order_info()
{
// 获取goods_id 和 order_id
$goods_id = request()->param('goods_id', '');
$order_num = request()->param('order_num', '');
if (empty($goods_id) || empty($order_num)) {
return $this->err('参数错误');
}
// 拼接文件路径
$filePath = './draw_log/' . $goods_id . '/' . $order_num . '.md';
// 获取文件路径参数
//$filePath = request()->param('file_path', '');
// 验证文件路径是否有效
if (empty($filePath) || !file_exists($filePath)) {
return $this->err('日志不存在');
}
// 检查文件扩展名
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
if (strtolower($extension) !== 'md') {
return $this->err('只支持查看Markdown文件(.md)');
}
// 读取文件内容
$content = file_get_contents($filePath);
// 将内容传递给视图
View::assign('file_path', $filePath);
View::assign('content', $content);
// 返回视图
return View::fetch("Markdown/index");
}
}