ajax php實現給fckeditor文字編輯器增加圖片刪除功能_網頁編輯器

來源:互聯網
上載者:User
工作需要需要fck編輯器的伺服器瀏覽加個圖片刪除的功能,我們利用ajax php實現的有需要的朋友可以參考下。
在fckeditoreditorfilemanagerbrowserdefault檔案夾中找到frmresourceslist.html檔案,修改代碼如下
oListManager.GetFileRowHtml找到這裡,下面代碼替換原來的代碼
複製代碼 代碼如下:

oListManager.GetFileRowHtml = function(fileName, fileUrl, fileSize) {
// Build the link to view the folder.
var sLink = '<a href="#" mce_href="#" onclick="OpenFile('' + ProtectPath(fileUrl) + '');return false;">選擇</a>';
// Get the file icon.
var sIcon = oIcons.GetIcon(fileName);
return '<div class="piclist"><img alt="" src="' + fileUrl + '" src2="images/icons/' + sIcon + '.gif" height="100" border="0"><p>' + sLink + ' <a href="#" mce_href="#" onclick="deleteFile('' + ProtectPath(fileUrl) + '');" style="color: #FF9933;" mce_style="color: #FF9933;"> 刪除 </a></p></div>'

}

在加個
<script type="text/javascript" src="/js/ajaxdel.js"></script>
ajaxdel.js檔案
複製代碼 代碼如下:

//******************************** 圖片刪除功能 ******************************************
var req; //定義變數,用來建立xmlhttprequest對象
//產生不重複的隨機數
var rn = Math.ceil(Math.random() * 1000000);
var rnch = rn;
function rndnum() {
while (rn == rnch) rn = Math.ceil(Math.random() * 1000000);
rnch = rn;
return rn;
}
// 刪除檔案,Ajax開始
function deleteFile(file) {
var url = "/ajaxpic.php?filePath=" + escape(file) + "&UD=" + rndnum(); //要請求的服務端地址
if (window.XMLHttpRequest) //非IE瀏覽器及IE7(7.0及以上版本),用xmlhttprequest對象建立
{
req = new XMLHttpRequest();
}
else if (window.ActiveXObject) //IE(6.0及以下版本)瀏覽器用activexobject對象建立,如果使用者瀏覽器禁用了ActiveX,可能會失敗.
{
req = new ActiveXObject("Microsoft.XMLHttp");
}
if (req) //成功建立xmlhttprequest
{
req.open("GET", url, true); //與服務端建立串連(請求方式post或get,地址,true表示非同步)
req.onreadystatechange = callback; //指定回呼函數
req.send(null); //發送請求
}
}
function callback() {
if(req.responseText ==1 )
{
alert('刪除成功!');
Refresh();
}
else
{
alert('刪除失敗!');
}//重新整理一下
}

ajaxpic.php檔案 儲存成ajaxpic.php
複製代碼 代碼如下:

<?
$root = dirname( __FILE__ );
$filePath = isset( $_GET['filePath'] ) ?$_GET['filePath']:'';
if( unlink( $root.$filePath) )
{
echo '1';
}
else
{
echo '0';
}
?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.