您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關如何實現php UEditor刪除圖片功能,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
php ueditor刪除圖片的實現方法:首先找到“uedior/dialogs/image/image.js”文件并修改Add內容;然后打開“mageManager.php”文件并添加內容為“function delfile()”即可。
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"; //處理確定按鈕的狀態(tài) 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 != '..') { $path3 = $path.'/'.$file; if (is_dir($path3)) { delfiles($fileName, $path3, $files); } else { if (preg_match("/\.(gif|jpeg|jpg|png|bmp)$/i", $file)) { $path4 = str_replace('../../', '/static/', $path3); $fileImg = basename($path4); if ($fileImg == $fileName) { $is_del = unlink($path3); } } } } } }
看完上述內容,你們對如何實現php UEditor刪除圖片功能有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業(yè)資訊頻道,感謝大家的支持。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。