知识点:1、PHP scandir() 函数; ;;函数返回指定目录中的文件和目录的数组。2、PHP is_dir() 函数; ;is_dir() 函数检查指定的文件是否是目录。3、递归4、PHP str_replace() 函数; ;;函数以其他字符替换字符串中的一
知识点:
1、PHP scandir() 函数 函数返回指定目录中的文件和目录的数组。
2、PHP is_dir() 函数 is_dir() 函数检查指定的文件是否是目录。
3、递归
4、PHP str_replace() 函数 函数以其他字符替换字符串中的一些字符
5、PHP unlink() 函数 unlink() 函数删除文件。
6、PHP file_exists() 函数 file_exists() 函数检查文件或目录是否存在。
common.php 文件夹添加,图片处理函数
// 图片资源处理函数
function my_scandir($dir=UEDITOR){
$flies=array();
$dir_list=scandir($dir);
foreach ($dir_list as $file) {
if($file != '.' && $file !=='..'){
if(is_dir($dir.'/'.$file)){//判断是否是文件夹
$flies[$file]=my_scandir($dir.'/'.$file); //递归
}else{
$flies[]=$dir.'/'.$file;
}
}
}
return $flies;
}
index.php 入口文件下定义:
// 定义ueditor目录
define('UEDITOR', __DIR__ . '/../../ueditor');
define('HTTP_UEDITOR','/ueditor');
define('DEL_UEDITOR', __DIR__ . '/../.././');
Ueditor 图片管理
// Ueditor图片管理
public function imglist()
{
$_files=my_scandir();
$files=array();
foreach ($_files as $k => $v) {
if(is_array($v)){
foreach ($v as $k1 => $v1) {
$v1=str_replace(UEDITOR,HTTP_UEDITOR,$v1);
$files[]=$v1;
}
}else{
$v=str_replace(UEDITOR,HTTP_UEDITOR,$v);
$files[]=$v;
}
}
$this->assign('img_Res',$files);
return view();
}
// 删除图片
public function delimg(){
$imgSrc=input('imgsrc');
$imgSrc = DEL_UEDITOR.$imgSrc;
if(file_exists($imgSrc)){//判断文件是否存在
if(@unlink($imgSrc)){
return json(['code'=>200,'message'=>'删除成功']);
}else{
return json(['code'=>500,'message'=>'删除失败']);
}
}
}
图片遍历到列表:
<table class="table table-striped table-hover table-bordered" id="editabledatatable">
<thead>
<tr role="row">
<th>
图片
</th>
<th class="text-center" width="14%;">
操作
</th>
</tr>
</thead>
<tbody>
{volist name="img_Res" id="img"}
<tr>
<td>
<img src="{$img}" alt="" width="70px"; height="70px">
</td>
<td align="center">
<a href="javascript:;" onclick="delimg(this,'{$img}')" class="btn btn-danger btn-xs delete"><i class="fa fa-trash-o"></i> 删除</a>
</td>
</tr>
{/volist}
</tbody>
</table>
ajax 删除:
<script>
function delimg(obj,objid){
if(!confirm('确定要删除么?')){
return false;
}
$.ajax({
url:"{:url('admin/Ueditor/delimg')}",
type:'POST',
data:{'imgsrc':objid},
datatype:'json',
success:function(data){
if(data.code==200){}
alert(data.message);
// history.go(0);
$(obj).parent().parent().remove();
}
})
}
</script>
沃梦达教程
本文标题为:Tp5 实现管理Ueditor 百度编辑器上传的图片


猜你喜欢
- laravel实现按月或天或小时统计mysql数据的方法 2023-02-22
- windows下9款一键快速搭建PHP本地运行环境的好工具(含php7.0环境) 2023-09-02
- PHP实现微信支付(jsapi支付)流程步骤详解 2022-10-09
- PHP中PDO事务处理操作示例 2022-10-15
- Laravel balde模板文件中判断数据为空方法 2023-08-30
- 用nohup命令实现PHP的多进程 2023-09-02
- laravel通用化的CURD的实现 2023-03-17
- php微信公众号开发之秒杀 2022-11-23
- PHP简单实现二维数组的矩阵转置操作示例 2022-10-02
- PHP仿tp实现mvc框架基本设计思路与实现方法分析 2022-10-18