使用php编写在线浏览日志文件的小应用
来源:互联网 发布:什么是世界货币 知乎 编辑:程序博客网 时间:2024/05/23 01:26
由于公司内部开发文件权限限制,非主管无法随意改动获取正式服文件,所以写了一个这样的小应用来查看日志文件
php文件
abstract class getDir{ protected $dir = null; protected $chmod = 0; protected $file = null; public function __construct($dir = null, $type = 0) { if (!$type) { if (empty($dir)) { $this->dir = dirname(__FILE__); } else { $this->dir = $dir; } } else { $this->dir = dirname(__FILE__); $this->file = dirname(__FILE__) . '/' . $dir; } $this->chmod = $this->getChmod($this->dir); } // 获取权限 protected function getChmod($filepath) { return substr(base_convert(@fileperms($filepath), 10, 8), -4); } public function get_chmod() { return $this->chmod; } public function get_dir() { return $this->dir; } abstract function readfile(); abstract function printFiles();}class getDirectory extends getDir{ public function printFiles() { $files = scandir($this->dir); echo <<< EODdir:{$this->dir}<br>EOD; echo <<< EODchmod:{$this->chmod}<br> EOD; foreach ($files as $item) { $d = mb_substr($item,0,1); if ($d == '.'){ continue; } echo <<< EOD<a href="?file=$item">$item</a><br>EOD; } } public function readfile() { if (is_file($this->file)) { $file_type = mb_substr($this->file, strrpos($this->file, '.') + 1); if ($file_type!='log'){ exit(sprintf("The file type is %s not log file!",$file_type)); } if (!is_writable($this->file)){ echo "The file can't read!"; } $chmod = $this->getChmod($this->file); echo <<< EOD dir:{$this->dir}<br> EOD; echo <<< EOD chmod:$chmod<br> EOD; $str = file_get_contents($this->file); $str = str_replace("\r\n","<br />",$str); echo $str; }else{ echo "This is not a file!"; } }}
使用
if (isset($_REQUEST['file'])) { $files = $_REQUEST['file']; $gd = new getDirectory($files, 1); $gd->readfile(); } else { $gd = new getDirectory(); $gd->printFiles(); }
日志目录(例子)
日志内容
0 0
- 使用php编写在线浏览日志文件的小应用
- pdf文件的在线浏览
- PDF.js插件的使用--在线浏览PDF文件
- atitit. web 在线文件管理器最佳实践(1)--- elFinder 的使用流程解决之道 。打开浏览服务器文件夹java .net php
- 用FLEX做文件的在线浏览
- PHP实现文件的浏览
- 在线浏览PDF文件
- 在线浏览swf文件
- PHP编写的小应用——计算器
- php 日志文件使用
- php 在线浏览word paf
- 在线浏览pdf文件实现
- 在线浏览PDF文件的实用jquery插件推荐
- 【转】在线浏览PDF文件的实用jquery插件推荐
- 在线浏览PDF文件的实用jquery插件推荐
- 使用php列出日志文件
- 使用 Xcode7 打包 HTML5+ 编写的应用 ipa 文件
- php使用指定的文件记录错误报告日志
- [Linux]:环境变量
- 结构体、联合体、枚举
- 构造第一个Filter过滤器
- Android软键盘(三)自动弹出键盘的现象
- A. Bachgold Problem
- 使用php编写在线浏览日志文件的小应用
- JQuery浮动层-01
- Bootstrap源码解读(第五弹:按钮)
- 做产品的一些碎碎念
- 欧拉计划 39
- RSA加密算法
- Basic Calculator
- WindowImplBase
- 经典算法(二):选择排序