簡體   English   中英

使用ck上傳圖片

[英]image uploading using ck

我需要使用ck編輯器中的發送到服務器按鈕將圖像上傳到服務器,並在ckeditor編輯區域中顯示該圖像。 在ckeditor中修改所有這些內容,如下所示,

url:在image.js中遵循此代碼的b.config.filebrowserImageBrowseLinkUrl我設置hidden = false;

CKEDITOR.editorConfig = function( config )
{
    config.filebrowserUploadUrl = '../ckeditorImage.jsp';
}

ckeditorImage.jsp is like this


try{

    String boundary="";
    String sz="";
    String fname="",sem="",sub="",mod="",empid="";
    Enumeration enum1 = request.getHeaderNames();
    while(enum1.hasMoreElements())
    {
            String header = (String)enum1.nextElement();
            String hvalue = request.getHeader(header);
            if("content-length".equalsIgnoreCase(header) )
        sz=""+hvalue;

    } 
        ServletInputStream sv=request.getInputStream();       
    int ch=0;
    String val="";  
    while((ch=sv.read())!=-1)
    {
        val+=(char)ch;      
                if(val.indexOf("Content-Type: ")>=0)
        {

            String tp="Content-Type: ";

            fname=val.substring(val.indexOf("filename=")+"filename=".length(),val.indexOf(tp));
                        fname=fname.replace('"',' ');
                        System.out.println(" =======fname============    :"+fname);           
            fname="home1.jpg";                  
            long size = fname.length();         

                        while((ch=sv.read())!='\n');
            byte[] b=new byte[Integer.parseInt(sz)];
            int cntr=0;
            while(cntr<b.length)
            {
                b[cntr]=(byte)sv.read();
                cntr++;
            }
                        String str=new String(b);
            int pos=str.indexOf(boundary)-2;
            pos=b.length;
            System.out.println(" =======fname============    :"+fname);  
                         File f=new File(config.getServletContext().getRealPath("/")+"/images/"+fname);
                         System.out.println(" creation of directory"+config.getServletContext().getRealPath("/")+"/images/"+fname);
                         System.out.println(" creation");
                       /*  if(f.isDirectory())
                         {
                             String fl[]=f.list();

                             for(int i=0;i<fl.length;i++)
                                 {
                                  File fd=new File(config.getServletContext().getRealPath("/")+"/users/"+sd+"/photos/"+fl[i]);
                                  fd.delete();
                             }
                         }*/
            if(!f.exists())
                f.mkdirs();
                         System.out.println(" creation of directory");
            java.io.FileOutputStream fout=new java.io.FileOutputStream(config.getServletContext().getRealPath("/")+"/images/"+fname);

            fout.write(b,2,pos-4);
            System.out.println(" creation of directory"+fout);
            fout.close();
        }
    }
    }
    catch(Exception e)
    {
        out.println(e);
    }

該項目還為您提供CKEditor的文件瀏覽器。

http://sourceforge.net/projects/jckconnector/

如果只需要上載部分,請查看servlet代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM