• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php UEditor如何实现删除图片功能

php 搞代码 4年前 (2022-01-04) 15次浏览 已收录 0个评论

php ueditor删除图片的实现方法:首先找到“uedior/dialogs/image/image.js”文件并修改Add内容;然后打开“mageManager.php”文件并添加内容为“function delfile()”即可。

推荐:《PHP视频教程》

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 = obj.getAttribute("tabSrc");
    for (var j = 0,
    length = tabBodys.length; j < length; j++) {
        var body = tabBodys[j],
        id = body.getAttribute("id");
        body.onclick = function() {
            this.style.zoom = 1;
        };
        if (id != tabSrc) {
            body.style.zIndex = 1;
        } else {
            body.style.zIndex = 200;
            //当切换到本地图片上传时,隐藏遮罩用的iframe
            if (id == "local") {
                toggleFlash(true);
                maskIframe.style.display = "none";
                //处理确定按钮的状态
                if (selectedImageCount) {
                    dialog.buttons[0].setDisabled(true);
                }
            } else {
                toggleFlash(false);
                maskIframe.style.display = "";
                dialog.buttons[0].setDisabled(false);
            }
            var list = g("imageList");
            list.style.display = "none";
            //切换到图片管理时,ajax请求后台图片列表
            if (id == "imgManager") {
                list.style.display = "";
                //已经初始化过时不再重复提交请求
                if (!list.children.length) {
                    ajax.request(editor.options.imageManagerUrl, {
                        timeout: 100000,
                        action: "get",
                        onsuccess: function(xhr) {
                            //去除空格
                            var tmp = utils.trim(xhr.responseText),
                            imageUrls = !tmp ? [] : tmp.split("ue_separate_ue"),
                            length = imageUrls.length;
                            g("imageList").innerHTML = !length ? "  " + lang.noUploadImage: "";
                            for (var k = 0,ci; ci = imageUrls[k++];) {
                                //Add Start===============================
                                var div = document.createElement("div");
                                var img = document.createElement("img");
                                var del = document.createElement("img");
                                var p = document.createElement("p");
 
                                div.appendChild(img);
                                div.appendChild(p);
                                p.appendChild(del);
                                div.style.display = "none";
 
                                img.style.height = "100px";
                                img.style.width = "100px";
                                del.setAttribute("src", "images/del.png");
                                p.style.marginTop = "-104px";
                                p.style.marginLeft = "90px";
 
                                g("imageList").appendChild(div);
                                img.onclick = function() {
                                    changeSelected(this);
                                };
 
                                del.onclick = function() {
                                    var me = this,
                                    src = me.getAttribute("alt", 2);
                                    var pic = me.parentNode.parentNode.childNodes[0];
                                    if (!confirm("删除操作不可恢复,您确认要删除本图片么?")) return;
                                    ajax.request(editor.options.imageManagerUrl, {
                                        action: "del",
                                        fileName: src.substr(src.lastIndexOf("/") + 1),
                                        onsuccess: function(xhr) {
                                            me.parentNode.parentNode.removeChild(pic);
                       <i style="color:transparent">来源gaodai$ma#com搞$代*码网</i>                     me.parentNode.removeChild(me);
                                        },
                                        one rror: function(xhr) {
                                            alert("服务器删除图片失败,请重试!");
                                        }
                                    });
                                };
                                //Add End================================
                                img.onload = function() {
                                    this.parentNode.style.display = "";
                                    var w = this.width,
                                    h = this.height;
                                    scale(this, 100, 120, 80);
                                    this.title = lang.toggleSelect + w + "X" + h;
                                    this.onload = null;
                                };
                                img.setAttribute(k < 35 ? "src": "lazy_src", editor.options.imageManagerPath + ci.replace(/\s+|\s+/ig, ""));
                                img.setAttribute("title", editor.options.imageManagerPath + ci.replace(/\s+|\s+/ig, ""));
                                img.setAttribute("width", "100px");
                                img.setAttribute("height", "100px");
 
                                del.onload = function() { //设置加载del图片时的样式
                                    this.style = "border:0";
                                    this.onload = null;
                                };
                                del.setAttribute("alt", editor.options.imageManagerPath + ci.replace(/\s+|\s+/ig, ""));
                            }
                        },
                        one rror: function() {
                            g("imageList").innerHTML = lang.imageLoadError;
                        }
                    });
                }
            }
            if (id == "imgSearch") {
                selectTxt(g("imgSearchTxt"));
            }
            if (id == "remote") {
                $focus(g("url"));
            }
        }
    }
}

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php UEditor如何实现删除图片功能
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址