TP 日志控制器

<?php
namespace app\index\controller;

use think\facade\Env;

class Log
{
    //tp5写法
    public function index()
    {
        header('Content-type:text/html; charset=utf-8');
        $path = request()->param('path', '');
        $path = str_replace('..', '-', $path);
        $runtime_path = Env::get('runtime_path');
        $filesnames = $runtime_path . $path;
        if (is_file($filesnames)) {
            echo '<pre>'. file_get_contents($filesnames). '</pre>';
        } else if (is_dir($filesnames)){
            $paths = scandir($filesnames);
            foreach ($paths as $key => $val) {
                echo '<a href="' . '?path=' . urlencode($path . '/' .  $val) . '">'.$val.'</a><br/>';
            }
        }

    }

}

tp3的写法
public function index(){
        header('Content-type:text/html; charset=utf-8');
        $module = I('module', 'Home');
        $date = I('date', date('Ymd'));
        $date = date('y_m_d', strtotime($date));
        echo LOG_PATH. $module. '/'. $date. '.log';
        if (file_exists(LOG_PATH. $module. '/'. $date. '.log')) {
            echo '<pre>'. file_get_contents(LOG_PATH. $module. '/'. $date. '.log' ). '</pre>';
        } else {
            echo LOG_PATH. $module. '/'. $date. '.log'. '文件不存在1';
        }

    }
赞赏

微信赞赏支付宝赞赏

发表评论