您好,欢迎访问一九零五行业门户网

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

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); me.parentnode.removechild(me); }, onerror: 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, "")); } }, onerror: function() { g("imagelist").innerhtml = lang.imageloaderror; } }); } } if (id == "imgsearch") { selecttxt(g("imgsearchtxt")); } if (id == "remote") { $focus(g("url")); } } }}
找到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); } } } } }}
以上就是php ueditor如何实现删除图片功能的详细内容。
其它类似信息

推荐信息