首页 > 代码库 > php版给UEditor的图片在线管理栏目增加图片删除功能

php版给UEditor的图片在线管理栏目增加图片删除功能

1.找到uedior/dialogs/image/image.js文件,Add为修改部分的代码:

/**
 * tab点击处理事件
 * @param tabHeads
 * @param tabBodys
 * @param obj
*/
function clickHandler(tabHeads, tabBodys, obj) {
    //head样式更改
    for (var k = 0,
    len = tabHeads.length; k < len; k++) {
        tabHeads[k].className = "";
    }
    obj.className = "focus";
    //body显隐
    var tabSrc = http://www.mamicode.com/obj.getAttribute("tabSrc");>

找到uedior/php/imageManager.php文件,增加以下内容:

if ($action == "del") {
    $fileName = $_POST['fileName'];
    foreach($paths as $path) {
        $str1 = delfiles($fileName, $path);
        break;
    }
}

function delfiles($fileName, $path, &$files = array()) {
    if (!is_dir($path)) return null;
    $handle = opendir($path);
    while (false !== ($file = readdir($handle))) {
        if ($file != '.' && $file != '..') {
            $path2 = $path.'/'.$file;
            if (is_dir($path2)) {
                delfiles($fileName, $path2, $files);
            } else {
                if (preg_match("/\.(gif|jpeg|jpg|png|bmp)$/i", $file)) {
                    $path3 = str_replace('../../', '/static/', $path2);
                    $fileImg = basename($path3);
                    if ($fileImg == $fileName) {
                        $is_del = unlink($path2);
                    }
                }
            }
        }
    }
}