久久久久av_欧美日韩一区二区在线_国产精品三区四区_日韩中字在线

返回列表 發(fā)帖
查看: 592|回復(fù): 0

[問題求助] 圖片黏貼上傳代碼

23

主題

47

回帖

78

積分

漸入佳境

貢獻(xiàn)
0 點(diǎn)
金幣
5 個
樓主
發(fā)表于 2024-11-10 23:48:40 | 只看樓主 |倒序?yàn)g覽 |閱讀模式


自己在谷歌搜索找到的,目前不知道如何使用有懂的希望告知一下。網(wǎng)頁端實(shí)現(xiàn)代碼

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     <script type="text/javascript" src="../../../template/default/style/cat/jquery.min.js"></script>
</head>

<body>
<div id="Msg" contentEditable="true" style="width: 600px; height:600px;border: 1px solid pink;"></div>
<script>
        //查找 Msg 元素,檢測當(dāng)粘貼時候,
        document.querySelector('#Msg').addEventListener('paste', function(e)
        {
                if (!(e.clipboardData && e.clipboardData.items)) {
                   return;
                 }
                 for (var i = 0, len = e.clipboardData.items.length; i < len; i++) {
                   var item = e.clipboardData.items;
                   console.log(item);
                   if (item.kind === "string") {
                         item.getAsString(function (str) {
                           console.log(str);
                           layer.msg("請粘貼圖片上傳", {
                                 icon: 2,
                                 shade: [0.3, '#000'],
                                 offset: '15px',
                                 time: 1000
                           })
                         })
                         $("#Msg").html(""); //jQuery方法一
                   } else if (item.kind === "file") {
                         var blob = item.getAsFile();
                         console.log('fff:');
                         console.log(blob);
                         if (blob.size === 0) {
                           return;
                         }
                         var data = new FormData();
                         data.append("image", blob);
                         $.ajax({
                           url: '/pastepic.php?ac=up_paste_img',
                           type: 'POST',
                           cache: false,
                           data: data,
                           processData: false,
                           contentType: false,
                           success: function (result) {
                                 console.log(result);
                                 //if (result.code == "0") {
                                   console.log(result.msg)
                                   //var html = "<img src=" + result.data + " width='100' height='100'>";
                                   //$("#Msg").html(html);
                                 //} else {
                                   console.log(result.msg)
                                 //}
                           }
                         });
                   }
                 }
        }, false);
</script>

</body>
</html>






服務(wù)器端php代碼
服務(wù)器端很簡單,直接使用discuzX3.5現(xiàn)成的上傳函數(shù)即可。

圖片處理函數(shù):pic_upload($file, 'album', 40, 30, 2)

圖片保存在album文件夾,同時生成jpg格式的縮略圖。

<?php
// mod文件只能被入口文件引用,不能直接訪問
if(!defined('IN_DISCUZ')) {
        exit('Access Denied');
}
require_once libfile('function/discuzcode');
require_once libfile('function/home');

$ac = dhtmlspecialchars($_GET['ac']); // 獲取數(shù)據(jù)動作,g1:取得某邊界內(nèi),某類別的所有點(diǎn)


if ($ac == 'up_paste_img'){
    //服務(wù)器端生成圖片
        echo 'will receive up_paste_img';
        //echo $_FILES;
        //print_r(array_values($_FILES));

        if(!empty($_FILES)) {
                foreach($_FILES as $varname => $file) {
                        if($file['tmp_name']) {
                                $result = pic_upload($file, 'album', 40, 30, 2);
                                $pic = 'album/'.$result['pic'];
                                echo '<br/>';
                                echo $pic;
                               
                        }
                }
        }

        exit;               
}
elseif ($ac == 'blank'){
    // 網(wǎng)頁模板
        include_once template("ccc/pic_paste");
}

?>


回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

  • 關(guān)注公眾號
  • 有償服務(wù)微信
  • 有償服務(wù)QQ

手機(jī)版|小黑屋|Discuz! 官方交流社區(qū) ( 皖I(lǐng)CP備16010102號 |皖公網(wǎng)安備34010302002376號 )|網(wǎng)站地圖|star

GMT+8, 2025-9-18 16:36 , Processed in 0.064793 second(s), 27 queries .

Powered by Discuz! W1.0 Licensed

Copyright © 2001-2025 Discuz! Team.

關(guān)燈 在本版發(fā)帖
有償服務(wù)QQ
有償服務(wù)微信
返回頂部
快速回復(fù) 返回頂部 返回列表