PHP、thinkPHP5.0开发网站文件管理功能(三)编辑文件

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

 

 

转载于:https://www.cnblogs.com/YAN-HUA/p/9083719.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值