Web 在线文件管理器学习笔记与总结(4)查看文件内容
② 查看文件内容
a.通过 file_get_contents($filename) 得到文件内容
b.通过 highlight_string($string) 或者 highlight_file($filename) 显示内容。使用 PHP 内置的语法高亮器所定义的颜色,打印输出或者返回输出或者返回语法高亮版本的 PHP 代码
当使用 file_get_contents 读取(php)文件的内容并且显示在页面上,可以使用 <textarea></textarea> 包裹输出的内容:
$content = file_get_contents($filename);
echo "<textarea cols='100' rows='10'>{$content}</textarea>";

index.php:
<?php
require 'dir.func.php';
require 'file.func.php';
require 'common.func.php';
$path = 'file';
$info = readDirectory($path); $act = @$_REQUEST['act'];
$filename = @$_REQUEST['filename'];
//跳转变量
$redirect = "index.php?path={$path}";
if($act == 'createFile'){
//创建文件
$mes = createFile($path.'/'.$filename);
alertMes($mes,$redirect);
}else if($act == 'showContent'){
//查看文件内容
$content=file_get_contents($filename);
//echo "<textarea readonly='readonly' cols='100' rows='10'>{$content}</textarea>";
//高亮显示PHP代码
//高亮显示字符串中的PHP代码
if(strlen($content)){
$newContent=highlight_string($content,true);
//高亮显示文件中的PHP代码
//highlight_file($filename);
$str=<<<EOF
<table width='100%' bgcolor='pink' cellpadding='5' cellspacing="0" >
<tr>
<td>$newContent</td>
</tr>
</table>
EOF;
echo $str;
}else{
alertMes("文件没有内容,请编辑再查看!",$redirect);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="cikonss.css" />
<link rel="stylesheet" href="common.css" />
</head>
<body>
<h1>在线文件管理器</h1>
<div id="top">
<ul id="navi">
<li><a href="index.php" title="主目录"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-home"></span></span></a></li>
<li><a href="#" onclick="show('createFile')" title="新建文件" ><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-file"></span></span></a></li>
<li><a href="#" title="新建文件夹"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-folder"></span></span></a></li>
<li><a href="#" title="上传文件"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-upload"></span></span></a></li>
<li><a href="#" title="返回上级目录"><span style="margin-left: 8px; margin-top: 0px; top: 4px;" class="icon icon-small icon-square"><span class="icon-arrowLeft"></span></span></a></li>
</ul>
</div>
<form action="index.php" method="post" enctype="multipart/form-data">
<table width='100%' border='1' cellpadding="5" cellspacing="0" bgcolor="#abcdef" align="center">
<tr id="createFolder" style="display:none;">
<td>请输入文件夹名称</td>
<td >
<input type="text" name="dirname" />
<input type="hidden" name="path" value="<?php echo $path;?>"/>
<input type="submit" name="act" value="创建文件夹"/>
</td>
</tr>
<tr id="createFile" style="display:none;">
<td>请输入文件名称</td>
<td >
<input type="text" name="filename" />
<input type="hidden" name="path" value="<?php echo $path;?>"/>
<input type="hidden" name='act' value='createFile'/>
<input type="submit" value="创建文件" />
</td>
</tr>
<tr id="uploadFile" style="display:none;">
<td >请选择要上传的文件</td>
<td ><input type="file" name="myFile" />
<input type="submit" name="act" value="上传文件" />
</td>
</tr>
<tr align="center">
<td>编号</td>
<td>名称</td>
<td>类型</td>
<td>大小</td>
<td>可读</td>
<td>可写</td>
<td>可执行</td>
<td>创建时间</td>
<td>修改时间</td>
<td>访问时间</td>
<td>操作</td>
</tr>
<?php
if($info['file']){
$i = 1;
foreach($info['file'] as $val){
$p = $path.'/'.$val;
?>
<tr align="center">
<td><?php echo $i;?></td>
<td><?php echo $val;?></td>
<td><?php $src = filetype($p) == 'file'?'file_ico.png':'folder_ico.png';?><img src="data:images/<?php echo $src;?>" alt="" title='文件'></td>
<td><?php echo transByte(filesize($p));?></td>
<td><?php $src = is_readable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" width="32" alt="" title='可读'></td>
<td><?php $src = is_writeable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" width="32" alt="" title='可写'></td>
<td><?php $src = is_executable($p)?'correct.png':'error.png';?><img src="data:images/<?php echo $src;?>" width="32" alt="" title='可写'></td>
<td><?php echo date('Y-m-d H:i:s',filectime($p));?></td>
<td><?php echo date('Y-m-d H:i:s',filemtime($p));?></td>
<td><?php echo date('Y-m-d H:i:s',fileatime($p));?></td>
<td>
<a href="index.php?act=showContent&filename=<?php echo $p;?>" title='查看'><img src="data:images/show.png" width="32" alt=""></a>
<a href="" title='修改'><img src="data:images/edit.png" width="32" alt=""></a>
<a href="" title='重命名'><img src="data:images/rename.png" width="32" alt=""></a>
<a href="" title='复制'><img src="data:images/copy.png" width="32" alt=""></a>
<a href="" title='剪切'><img src="data:images/cut.png" width="32" alt=""></a>
<a href="" title='删除'><img src="data:images/delete.png" width="32" alt=""></a>
<a href="" title='下载'><img src="data:images/download.png" width="32" alt=""></a>
</td>
</tr>
<?php
$i++;
}
}
?>
</table>
</form>
<script src='common.js'></script>
</body>
</html>
Web 在线文件管理器学习笔记与总结(4)查看文件内容的更多相关文章
- Web 在线文件管理器学习笔记与总结(19)上传文件
dir.func.php 中添加方法: /* 上传文件 */ function uploadFile($fileInfo,$path,$allowExt = array('jpg','jpeg','p ...
- Web 在线文件管理器学习笔记与总结(17)复制文件 (18)剪切文件
(17)复制文件 ① 复制文件通过copy($src,$dst) 来实现 ② 检测目标目录是否存在,如果存在则继续检测目标目录中是否存在同名文件,如果不存在则复制成功 file.func.php 中添 ...
- Web 在线文件管理器学习笔记与总结(15)剪切文件夹 (16)删除文件夹
(15)剪切文件夹 ① 通过rename($oldname,$newname) 函数实现剪切文件夹的操作 ② 需要检测目标文件夹是否存在,如果存在还要检测目标目录中是否存在同名文件夹,如果不存在则剪切 ...
- Web 在线文件管理器学习笔记与总结(13)重命名文件夹(14)复制文件夹
(13)重命名文件夹 ① 重命名文件夹通过 rename($oldname,$newname) 实现 ② 检测文件夹名是否符合规范 ③ 检测当前目录中是否存在同名文件夹名称,如果不存在则重命名成功 i ...
- Web 在线文件管理器学习笔记与总结(11)获取文件夹信息 (12)返回上一级操作
(11)获取文件夹信息 文件夹没有修改操作. index.php: <?php require 'dir.func.php'; require 'file.func.php'; require ...
- Web 在线文件管理器学习笔记与总结(10)查看文件夹中的内容
① 读取文件夹大小 a. 封装计算文件夹大小的函数 b. 打开文件夹 c. 循环判断文件夹下的内容是文件还是文件夹,如果是文件,则累积相加文件的大小:如果是文件夹,则递归调用该函数 注意两个问题: ...
- Web 在线文件管理器学习笔记与总结(9)下载文件
① 普通形式的文件可以使用超链接形式下载 <a href = '下载文件名'>点击下载</a> ② 如果下载图片.html 等类型的文件,使用header() 函数发送网页头信 ...
- Web 在线文件管理器学习笔记与总结(8)删除文件
unlink($filename) 删除文件 index.php: <?php require 'dir.func.php'; require 'file.func.php'; require ...
- Web 在线文件管理器学习笔记与总结(7)重命名文件
rename($oldname,$newname) 重命名文件或目录 <<<EOF EOF; 使用heredoc 技术,来部分实现界面与代码的准分离 重命名时,需要验证新文件名的合法 ...
- Web 在线文件管理器学习笔记与总结(6)jQuery UI 预览图片
① 查看文件内容,如果文件是图片类型,点击直接查看图片: ② 如果不是图片类型,显示文件中的内容: ③ 使用 jQuery UI 中的 Dialog 显示图片 a.引入: <script src ...
随机推荐
- swift复合类型
1.元组类型 (tuple) 元组就是多个元素的组合,是一个用圆括号括起来分号分隔的多个数据的一个集合体. 例如:定义一个学生变量,要求姓名 jim,年龄 19,性别 male 的元组变量为 // ...
- (*p)++和*(p++)和*p++的区别
* 和++优先级是同一级别,同一级别按照从右往左的顺序计算 所以: *p++等价于*(p++) #define debug(x) cout << #x << " a ...
- jquery easy ui 1.3.4 快速入门(1)
什么是easyui jQuery EasyUI是一组基于jQuery的UI插件集合,而jQuery EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面.开发者不需要编写复杂 ...
- 【bzoj2002】[Hnoi2010]Bounce 弹飞绵羊 分块
[bzoj2002][Hnoi2010]Bounce 弹飞绵羊 2014年7月30日8101 Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀 ...
- MATLAB学习笔记(十一)——MATLAB图形用户界面设计
(一)菜单设计 一.建立用户菜单 1.概况: 用户菜单一般含有一级菜单和二级菜单,乃至多级菜单.每一级菜单又包含多个菜单项.建立菜单可以使用uimenu函数. 2.uimenu函数调用: %建立一级菜 ...
- 【转】apache kafka技术分享系列(目录索引)
转自: http://blog.csdn.net/lizhitao/article/details/39499283 估计大神会不定期更新,所以还是访问这个链接看最新的目录list比较好 apa ...
- python 出入任意多个参数
def __init__(self, name, gender, birth, **kw): self.name = name self.gender = gender self.birth = bi ...
- Spring的bean标签
Spring框架中主要有四种标签bean.alias.import.beans,其中bean标签是其他标签的基础. 一.bean标签的属性 scope:用来配置spring bean的作用域 sing ...
- Ajax本地跨域问题
问题:打开本地html文件时,,报错如下 Cross origin requests are only supported for protocol schemes: http, data,chrom ...
- HDU3987 Harry Potter and the Forbidden Forest(边数最少的最小割)
方法1:两遍最大流.一遍最大流后,把满流边容量+1,非满流边改为INF:再求最小割即为答案. 我大概想了下证明:能构成最小割的边在第一次跑最大流时都满流,然后按那样改变边容量再求一次最小割,就相当于再 ...