天天看點

本地圖文直接複制到HTML編輯器中

本地圖文直接複制到HTML編輯器中

如何做到 ueditor批量上傳word圖檔?

1、前端引用代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <meta http-equiv="Content-Type"content="text/html; charset=utf-8"/>

   <title>編輯器完整版執行個體-1.2.6.0</title>

    <script type="text/javascript"src="ueditor.config.js"charset="utf-8"></script>

    <script type="text/javascript"src="ueditor.all.js"charset="utf-8"></script>

    <link type="text/css"rel="Stylesheet"href="WordPaster/css/WordPaster.css"/>

    <link type="text/css"rel="Stylesheet"href="WordPaster/js/skygqbox.css"/>

    <scrip ttype="text/javascript"src="WordPaster/js/json2.min.js"charset="utf-8"></script>

    <scrip ttype="text/javascript"src="WordPaster/js/jquery-1.4.min.js"charset="utf-8"></script>

    <scrip ttype="text/javascript"src="WordPaster/js/WordPaster.js"charset="utf-8"></script>

    <scrip ttype="text/javascript"src="WordPaster/js/skygqbox.js"charset="utf-8"></script>

</head>

<body>

    <textarea name="背景取值的key"id="myEditor">這裡寫你的初始化内容</textarea>

    <script type="text/javascript">

        var pasterMgr = new WordPasterManager();

    pasterMgr.Config["PostUrl"] = "http://localhost:81/WordPaster2/WordPasterUEditor1x/php/upload.php"

    pasterMgr.Load();//加載控件

          UE.getEditor('myEditor',{onready:function(){//建立一個編輯器執行個體

              pasterMgr.SetEditor(this);

          }});

    </script>

</body>

</html>

請求

檔案上傳的預設請求是一個檔案,作為具有“upload”字段的表單資料。

響應:檔案已成功上傳

當檔案成功上傳時的JSON響應:

uploaded- 設定為1。

fileName - 上傳檔案的名稱。

url - 上傳檔案的URL。

響應:檔案無法上傳

uploaded- 設定為0。

error.message - 要顯示給使用者的錯誤消息。

2、粘貼word裡面的圖檔路徑是fill://D 這種格式 我了解這種是非浏覽器安全的 許多浏覽器也不支援

目前項目是用了一種變通的方式:

先把word上傳到背景 、poi解析、存儲圖檔 、轉換html、替換圖檔、放到富文本框裡顯示

(富文本顯示有個坑:沒找到直接給富文本指派的方法 要先銷毀 記錄下

success : function(data) {

     $('#content').attr('value',data.imagePath);

     var editor = CKEDITOR.instances["content"]; //你的編輯器的"name"屬性的值

     if (editor) {

       editor.destroy(true);//銷毀編輯器

      }    

     CKEDITOR.replace('content'); //替換編輯器,editorID為ckeditor的"id"屬性的值

     $("#content").val(result);    //對editor指派

     //CKEDITOR.instances.contentCkeditor.setData($("#content").text());

 }

3.接收上傳的圖檔并儲存在服務端

<?php

ob_start();

//201201/10

$timeDir =date("Ym")."/".date("d");

$uploadDir =dirname(__FILE__).'/upload/'.$timeDir;

$curDomain = "http://".$_SERVER["HTTP_HOST"]."/";

//相對路徑 http://www.ncmem.com/upload/2012-1-10/

$relatPath = $curDomain ."WordPaster2/WordPasterUEditor1x/php/upload/" . $timeDir . "/";

//自動建立目錄。upload/2012-1-10

if(!is_dir($uploadDir))

{

mkdir($uploadDir,0777,true);

}

//如果PHP頁面為UTF-8編碼,請使用urldecode解碼檔案名稱

//$fileName = urldecode($_FILES['postedFile']['name']);

//如果PHP頁面為GB2312編碼,則可直接讀取檔案名稱

$fileName = $_FILES['file']['name'];

$tmpName = $_FILES['file']['tmp_name'];

//取檔案擴充名jpg,gif,bmp,png

$path_parts =pathinfo($fileName);

$ext = $path_parts["extension"];

$ext =strtolower($ext);//jpg,png,gif,bmp

//隻允許上傳圖檔類型的檔案

if($ext == "jpg"

    || $ext == "jpeg"

    || $ext == "png"

    || $ext == "gif"

    || $ext == "bmp")

    //年_月_日_時分秒毫秒.jpg

    $saveFileName = $fileName;

    //xxx/2011_05_05_091250000.jpg

    $savePath = $uploadDir . "/" . $saveFileName;

    //另存為新檔案名稱

    if (!move_uploaded_file($tmpName,$savePath))

    {

exit('upload error!' . "檔案名稱:" .$fileName . "儲存路徑:" . $savePath);

    }

//輸出圖檔路徑

//$_SERVER['HTTP_HOST']   localhost:81

//$_SERVER['REQUEST_URI'] /FCKEditor2.4.6.1/php/test.php

$reqPath =str_replace("upload.php","",$_SERVER['REQUEST_URI']);

echo $relatPath .  $saveFileName;

header('Content-type: text/html; charset=utf-8');

header('Content-Length: ' .ob_get_length());

?>

效果展示: