知识点:
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>