PHP、thinkPHP5.0开发网站文件管理功能(三)编辑文件
2024-09-27 22:52:24
public function edit(){
$file = iconv('UTF-8','GB2312',urldecode(input('file')));
if(empty($file)|| !file_exists($file)){
$this->error('操作异常');
}
$arr = ['.PHP', '.CSS', '.JS', '.XML', '.HTML', '.HTACCESS','.TXT','.JSON'];
$exc = strtoupper(substr($file,strrpos($file,'.')));
if (!in_array($exc, $arr)) {
$this->error("该文件类型不支持编辑");
}
if(request()->isPost()){
$content = input('code');
//打开要编辑的文件
$fp = fopen($file,'w');
//写入新内容
fwrite($fp,$content);
//关闭文件
fclose($fp);
$this->success('文件保存成功','file/index');
}
$code = htmlentities(file_get_contents($file),ENT_COMPAT,'UTF-8');//获取文件的内容,把HTML转为实体内容输出把代码展示在页面
$this->assign('code',$code);
$this->assign('currfile',$file);
$this->assign('ext', $exc);
return view("file_edit");
}
前端编辑界面推荐使用codemirror插件,能显示行数和高亮代码
最新文章
- Java|今天起,别再扯订阅和回调函数
- About next_permutation
- java selenium (一) selenium 介绍
- 在web中使用windows控件,实现摄像头功能
- iOS NSDate与NSString相互转化
- 如何用分析函数找出EMP表中每个部门工资最高的员工
- [原创]Android Studio的Instant Run(即时安装)原理分析和源码浅析
- performSelector:withObject:afterDelay: 精要概览(持续更新)
- Ubuntu的一些常用快捷键
- CSS系列:less备忘
- 编写javascript、Jquery的String.format();
- Struts2入门学习
- 基于B/S模式的推送
- Forward reference vs. forward declaration
- Android如何创建背景透明的Dialog
- 简单的javascript实例一(时钟特效)
- hystrix学习
- Makefile ------ $@ $^ %<; 使用
- OpenResty 最佳实践 1
- python 保留两位小数