| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 653 人关注过本帖
标题:fckeditor编辑器远程图片上传功能的图片路径问题。
只看楼主 加入收藏
大牙牙大
Rank: 1
等 级:新手上路
帖 子:3
专家分:7
注 册:2012-2-29
收藏
 问题点数:0 回复次数:1 
fckeditor编辑器远程图片上传功能的图片路径问题。
我下载了一个别人增强过的fckeditor编辑器,里面有个远程图片上传的插件。
但是图片上传到服务器后返回给编辑器中的图片路径会被带上域名,如http://127.0.0.1/upfiles/xx.jpg,如果网站换个域名图片就显示不出来了。我想把它变成/upfiles/xx.jpg或者相对路径。
百度 GOOGLE 也搜索不到解决办法。自己又不知道在哪个位置改,求各位大大指点下迷津。万分感谢。
下面是JS代码。
程序代码:
<script type="text/javascript" language="javascript">
    window.parent.SetOkButton( false ) ;
function $(element){
  if (arguments.length>1){
    for (var i=0, elements=[], length=arguments.length; i<length; i++)
      elements.push($(arguments[i]));
    return elements;
  }
  if (typeof element =='string') element=document.getElementById(element);
  return element;
}

    var oEditor = window.parent.InnerDialogLoaded() ;

    function OnLoad()
    {

    oEditor.FCKLanguageManager.TranslatePage( document ) ;

    var innerTxt="";
    var imgs = oEditor.FCK.EditorWindow.document.body.all.tags("img") ;
    //var imgs = window.opener.document.body.all.tags("img") ;
    if (imgs.length>0)
    {var remoteList = new Array();
    var localList = new Array();
    var flag;
    for (var i=0; i<imgs.length; i++){
        if(i==0){remoteList[i] = imgs[i].src;}
        else{flag=false;
            for (var j=0; j<remoteList.length; j++)
            {
            if(remoteList[j]==imgs[i].src){flag=true;break;}
            }
            if(!flag) {remoteList[i]=imgs[i].src;}
        }
    }
    for (var k=0; k<remoteList.length; k++)
    {
        if(!(typeof remoteList[k] == "undefined"))
        innerTxt += (k+1)+"<input name=\"imgs\" type=\"checkbox\" value=\""+remoteList[k]+"\""+(IsRemotePic(remoteList[k])?" checked":"")+" onclick=\"btnStat()\" />"+remoteList[k]+"<br />";
    }
    }else{innerTxt+="没有找到图片资料";$("btnSaveRemote").disabled=true;}
    $("Anylysis").innerHTML = innerTxt;
    btnStat();
    //document.write(GetCheckNum("imgs"));
    //window.parent.SetAutoSize( true ) ;
    }
    function IsRemotePic(ss){
    if(typeof ss=="undefined" || ss==null) return false;
    var local=window.location.protocol+"//"+window.location.host;
    if(ss.substr(0,local.length)!=local){return true;}else{return false;}
    }

function btnStat()
{
    $('btnSaveRemote').disabled =
        ( GetCheckNum("imgs")==0 ) ;
    $("domAllFilesCount").innerHTML=GetCheckNum("imgs");

}
function GetCheckNum(objName){
var ii=0;
//obj=eval("document.all."+objName)
obj=eval("document.getElementsByName('"+objName+"')");
if(typeof obj != "object") return ii;
var inum=obj.length;
for(var i=0; i<inum; i++){
if(obj[i].checked == 1) ii=ii+1;
}
return ii;
}
function createXMLHttpRequest() {
  if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();               
  }
}
function Ok()
{
    if ( document.getElementsByName('imgs').length == 0 ) return ;
    $("Uploading").style.display="block";
    $("btnSaveRemote").disabled=true;
    var imgs=document.getElementsByName("imgs");

    var xmlDoc = new ActiveXObject("msxml2.FreeThreadedDOMDocument");
    //xmlDoc.LoadXML('?xml version="1.0" encoding="utf-8"?><root><img>img1111</img><img>img222</img></root');
    var p=xmlDoc.createProcessingInstruction("xml","version='1.0' encoding='utf-8'");
    xmlDoc.appendChild(p);
    var root=xmlDoc.createNode(1,"imgs","");

    var status=xmlDoc.createNode(1,"status","");

    var total=xmlDoc.createAttribute("total");
    total.value=imgs.length+1;
    status.setAttributeNode(total);
    var curr=xmlDoc.createAttribute("curr");
    curr.value="";
    status.setAttributeNode(curr);
    var currfile=xmlDoc.createAttribute("currfile");
    currfile.value="";
    status.setAttributeNode(currfile);

    root.appendChild(status);
    for(var i=0;i<imgs.length;i++){
      if(imgs[i].checked==1){
        var n=xmlDoc.createNode(1,"img","");
        var r=xmlDoc.createAttribute("src");
        r.value=imgs[i].value;
        n.setAttributeNode(r);
        root.appendChild(n);
      }
    }
    xmlDoc.appendChild(root);

    var myAjax=new Ajax();
    var url="save.asp"
    if(myAjax.Create(true)){
      myAjax.Send(url, $("data"), $("domProgressBarId"), xmlDoc);
    }

}
function Ajax(){
var XmlHttp = null;
var DataObject = null;//数据接收对象
var LoadingBar = null;//状态显示对象
var LoadingMax = 100;//进度条最大值
var LoadingWidth = null;//保存宽度,还原初始属性
var LoadingTimer = 10;//刷新时间
var LoadingTimerID = null;//时间ID
var FinishTimer = 10;//完成停留时间,等候进度条完成
var FinishTimerID = null;//时间ID
var HttpState = 0;
var CanFree = false;//释放
this.Create = function(free){
   try{
    if(free)CanFree = true;
    if(navigator.appName.indexOf("Netscape")==-1){
     try{
            XmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
     }catch(e){
      XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");  
     }
        }else{
           XmlHttp=new XMLHttpRequest();
        }
     return true;
   }catch(e2){
    return false;
   }
}
this.Send = function(url, obj1, obj2, data){
   try{
    DataObject = obj1;
    LoadingBar = obj2;
    if(LoadingBar){
     LoadingMax = LoadingBar.offsetWidth;//保存可见宽度
     LoadingWidth = LoadingBar.style.width;//可能会没有设置宽度,这时数据为空
     LoadingBar.style.width = "0px";
     LoadingBar.innerHTML = "0%";
     LoadingBar.style.display = "";
     DataObject.style.display = "none";
     HttpState = 0;
     if(LoadingTimerID)clearInterval(LoadingTimerID);//清空时钟
     LoadingTimerID = setInterval(this.StatusBar, LoadingTimer);
    }
      XmlHttp.open("POST", url, true);
      XmlHttp.SetRequestHeader("content-type", "text/xml");
      XmlHttp.onreadystatechange = this.StateChange;
    XmlHttp.send(data);
    return true;
   }catch(e){
    return false;
   }
}
this.StateChange = function(){
   try{
    if(XmlHttp.readyState)HttpState = XmlHttp.readyState;
      if (XmlHttp.readyState == 4) {
     if(LoadingTimerID)clearInterval(LoadingTimerID);//清空时钟
     if(LoadingBar){
      LoadingBar.style.width = LoadingWidth;
      LoadingBar.innerHTML = "100%";
      if(FinishTimerID)clearInterval(FinishTimerID);//清空时钟
      FinishTimerID = setInterval(this.Finish, FinishTimer);
     }else{
      //DataObject.innerHTML = XmlHttp.responseText;
      if(CanFree)this.Destroy();
     }
      }
 
    this.Finish = function(){//放到外面访问不了
     if(FinishTimerID)clearInterval(FinishTimerID);//清空时钟
     //LoadingBar.style.display = "none";
     //DataObject.style.display = "";
     //DataObject.innerHTML = XmlHttp.responseXML.xml;
    var items=XmlHttp.responseXML.selectNodes("//imgs/img");
    var old=oEditor.FCK.EditorWindow.document.body.innerHTML;
    for (var i=0; i<items.length; i++){
      var ss=items[i].attributes[0].nodeValue;
      var dd=items[i].attributes[1].nodeValue;
      ss=ss.replace(/\//gi,"\/");
      ss=ss.replace(/\./gi,"\.");
      ss=ss.replace(/\+/gi,"\+");
      ss=ss.replace(/\*/gi,"\*");
      ss=ss.replace(/\?/gi,"\?");
      var re=new RegExp(ss,"gi");
      old=old.replace(re,dd);
      }
      oEditor.FCK.EditorWindow.document.body.innerHTML=old;
      var status=XmlHttp.responseXML.selectSingleNode("//imgs/status");
      if(status!=null){
      var curr=status.selectSingleNode("./@curr");
      var currfile=status.selectSingleNode("./@currfile");
      $("domAlreadyDownloadFilesCount").innerHTML=curr.nodeValue;
      $("domCurrentFile").innerHTML=currfile.nodeValue;}
      $("Uploading").style.display="none";
     if(CanFree)this.Destroy();
    }
  
    this.Destroy = function(){
     if(LoadingTimerID)clearInterval(LoadingTimerID);//清空时钟
     if(FinishTimerID)clearInterval(FinishTimerID);//清空时钟
     XmlHttp = null;
    }
  
   }catch(e){}
}
this.StatusBar = function(){
   try{
    if(LoadingBar.offsetWidth >= LoadingMax){
     LoadingBar.innerHTML = "100%";
     LoadingBar.style.width = LoadingWidth;
     return;//返回
    }
  
    if(LoadingBar.offsetWidth < (HttpState + 1) * Math.floor(LoadingMax / 4)){
     var loading = LoadingBar.offsetWidth + Math.floor(LoadingMax / 40);//十分之一
     LoadingBar.style.width = loading + "px";
     var percen = Math.floor(loading / LoadingMax * 100);
     LoadingBar.innerHTML = (percen>100?100:percen) + "%";
    }else{
     LoadingBar.style.width = (HttpState + 1) * Math.floor(LoadingMax / 4) + "px";
     LoadingBar.innerHTML = Math.floor(100 / (4 - HttpState)) + "%";
    }
   }catch(e){}
}
this.Destroy = function(){
   if(LoadingTimerID)clearInterval(LoadingTimerID);//清空时钟
   if(FinishTimerID)clearInterval(FinishTimerID);//清空时钟
   XmlHttp = null;
}
}
    </script>

 
搜索更多相关主题的帖子: 图片 function element GOOGLE 
2012-08-22 12:35
大牙牙大
Rank: 1
等 级:新手上路
帖 子:3
专家分:7
注 册:2012-2-29
收藏
得分:0 
我在“oEditor.FCK.EditorWindow.document.body.innerHTML=old;”的下面加个一个alert(old);
输出来的图片路径是绝对路径,/upfiles/xx.jpg,没有带上域名的,但是为什么返回给编辑器后会带上域名呢。
2012-08-22 12:52
快速回复:fckeditor编辑器远程图片上传功能的图片路径问题。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036823 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved