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插件,能显示行数和高亮代码

												

最新文章

  1. Java|今天起,别再扯订阅和回调函数
  2. About next_permutation
  3. java selenium (一) selenium 介绍
  4. 在web中使用windows控件,实现摄像头功能
  5. iOS NSDate与NSString相互转化
  6. 如何用分析函数找出EMP表中每个部门工资最高的员工
  7. [原创]Android Studio的Instant Run(即时安装)原理分析和源码浅析
  8. performSelector:withObject:afterDelay: 精要概览(持续更新)
  9. Ubuntu的一些常用快捷键
  10. CSS系列:less备忘
  11. 编写javascript、Jquery的String.format();
  12. Struts2入门学习
  13. 基于B/S模式的推送
  14. Forward reference vs. forward declaration
  15. Android如何创建背景透明的Dialog
  16. 简单的javascript实例一(时钟特效)
  17. hystrix学习
  18. Makefile ------ $@ $^ %< 使用
  19. OpenResty 最佳实践 1
  20. python 保留两位小数

热门文章

  1. Blender 安装
  2. git clone Timed out 解决
  3. Postman工具---请求与响应
  4. java后台对json格式数据的解析
  5. Struts2返回JSON数据的具体应用范例
  6. 数据结构--树--AVL树
  7. [译]Javascript timing事件
  8. excel导入工具
  9. css笔记-1
  10. python(二):可变参数