{"id":927,"date":"2018-03-22T10:14:17","date_gmt":"2018-03-22T02:14:17","guid":{"rendered":"http:\/\/www.rain1024.com\/?p=927"},"modified":"2023-08-07T20:57:26","modified_gmt":"2023-08-07T12:57:26","slug":"article114","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2018\/03\/22\/article114\/","title":{"rendered":"PHP\u4f7f\u7528summernote\u7f16\u8f91\u5668"},"content":{"rendered":"<h1>PHP\u4f7f\u7528summernote\u7f16\u8f91\u5668<\/h1>\n<h2>summernote\u662f\u4e00\u4e2a\u5f88\u597d\u7528\u7684\u7f16\u8f91\u5668\uff0c\u7b80\u5355\u5927\u65b9\uff0c\u57fa\u672c\u529f\u80fd\u90fd\u6709\uff0c\u6211\u53ea\u8bb0\u5f55\u4f7f\u7528\u56fe\u7247\u4e0a\u4f20\u63a5\u53e3\u548c\u83b7\u53d6\u5185\u5bb9\u63a5\u53e3\u529f\u80fd\u7684\u6f14\u793a\uff0c\u5176\u4ed6\u7684\u529f\u80fd\u6682\u65f6\u8fd8\u6ca1\u6709\u7528\u5230\uff0c\u4e0b\u9762\u662fsummernote\u7f16\u8f91\u5668\u7684\u6837\u5b50<\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/cos.rain1024.com\/blog\/php\/php61.jpg\" alt=\"\" \/><\/p>\n<h2>1.summernote\u754c\u9762\u7684\u4ee3\u7801<\/h2>\n<pre><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;title&gt;\u56fe\u96c6\u5185\u5bb9\u4e0a\u4f20&lt;\/title&gt;\n    &lt;link href=\"http:\/\/netdna.bootstrapcdn.com\/bootstrap\/3.3.5\/css\/bootstrap.css\" rel=\"stylesheet\"&gt;\n    &lt;script src=\"http:\/\/cdnjs.cloudflare.com\/ajax\/libs\/jquery\/2.1.4\/jquery.js\"&gt;&lt;\/script&gt;\n    &lt;script src=\"http:\/\/netdna.bootstrapcdn.com\/bootstrap\/3.3.5\/js\/bootstrap.js\"&gt;&lt;\/script&gt;\n    &lt;link href=\"http:\/\/cdnjs.cloudflare.com\/ajax\/libs\/summernote\/0.8.3\/summernote.css\" rel=\"stylesheet\"&gt;\n    &lt;script src=\"http:\/\/cdnjs.cloudflare.com\/ajax\/libs\/summernote\/0.8.3\/summernote.js\"&gt;&lt;\/script&gt;\n\n    &lt;link rel=\"stylesheet\" href=\"\/public\/static\/assets\/css\/amazeui.min.css\" \/&gt;\n&lt;\/head&gt;\n&lt;body style=\"width: 80%;margin: auto;\" &gt;\n&lt;form method=\"post\" action=\"\/index.php\/admin\/picture\/form\" id=\"myform\"&gt;\n    &lt;div id=\"summernote\" &gt;123&lt;\/div&gt;\n    &lt;input type=\"hidden\" name=\"content\" id=\"content\" value=\"\"&gt;\n    &lt;div class=\"am-form-group\" align=\"center\"&gt;\n        &lt;div class=\"am-u-sm-12\" &gt;\n            &lt;button  type=\"button\" class=\"am-btn am-btn-default am-btn-danger\" onclick=\"submit_content()\"&gt;\u4fdd\u5b58\u5185\u5bb9&lt;\/button&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/form&gt;\n\n\n&lt;script&gt;\n    function submit_content(){\n        var content = $('#summernote').summernote('code');\n        document.getElementById('content').value = content;\n        document.getElementById('myform').submit();\n    }\n    $(document).ready(function() {\n        var summernote = $('#summernote').summernote({\n            maxHeight: 500,\n            minHeight: 400,\n            lang: 'zh-CN',\n            focus: true,\n            callbacks:{\n                onImageUpload: function(files,editor,$editable){\n                    sendFile(files);\n                }\n            }\n        });\n    });\n    \/\/\u9009\u62e9\u56fe\u7247\u65f6\u628a\u56fe\u7247\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u518d\u8bfb\u53d6\u670d\u52a1\u5668\u6307\u5b9a\u7684\u5b58\u50a8\u4f4d\u7f6e\u663e\u793a\u5728\u5bcc\u6587\u672c\u533a\u57df\u5185\n    function sendFile(files, editor, $editable) {\n        var formdata = new FormData();\n        formdata.append(\"file\", $('.note-image-input')[0].files[0]);\n        $.ajax({\n            data : formdata,\n            type : \"POST\",\n            url : \"\/index.php\/admin\/picture\/upload_image\", \/\/\u56fe\u7247\u4e0a\u4f20\u51fa\u6765\u7684url\uff0c\u8fd4\u56de\u7684\u662f\u56fe\u7247\u4e0a\u4f20\u540e\u7684\u8def\u5f84\uff0chttp\u683c\u5f0f\n            cache : false,\n            contentType : false,\n            processData : false,\n            dataType : \"json\",\n            success: function(data) {\n\/\/                alert(data);\n                \/\/data\u662f\u8fd4\u56de\u7684hash,key\u4e4b\u7c7b\u7684\u503c\uff0ckey\u662f\u5b9a\u4e49\u7684\u6587\u4ef6\u540d\n                $('#summernote').summernote('insertImage', data);\n            },\n            error:function(){\n                alert(\"\u4e0a\u4f20\u5931\u8d25\");\n            }\n        });\n    }\n&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n\n<\/code><\/pre>\n<h2><code>var content = $('#summernote').summernote('code');<\/code>\u8fd9\u6bb5\u4ee3\u7801\u53ef\u4ee5\u83b7\u53d6\u5230\u7f16\u8f91\u5668\u4e2d\u7684\u5185\u5bb9<\/h2>\n<h2>sendfile\u51fd\u6570\u4e2d\uff0curl\u8868\u793a\u56fe\u7247\u4e0a\u4f20\u5230PHP\u51fd\u6570\u7684\u5730\u5740\uff0c\u8fd4\u56de\u503c\u4e3ajson\u683c\u5f0f\u7684\u56fe\u7247\u5730\u5740<\/h2>\n<h2>\u4e0b\u9762\u662fthinkphp5\u4e2d\u7684\u4ee3\u7801<\/h2>\n<pre><code>public function upload_image($name){\n        $image = \\request()-&gt;file($name);\n        if($image){\n            \/**\n             * \/\/\u5224\u65ad\u56fe\u7247\u6587\u4ef6\u7684\u683c\u5f0f\n             * \u5224\u65ad\u56fe\u7247\u5927\u5c0f \u6700\u5927\u4e3a10mb\n             *\/\n            $info = $image-&gt;validate(['size'=&gt;10000000,'ext'=&gt;'jpg,png,jpeg'])-&gt;move(ROOT_PATH . 'public' . DS . 'uploads');\n\/\/             echo $info-&gt;getSize();\n\/\/        $info-&gt;getExtension()   \/\/\u5224\u65ad\u56fe\u7247\u6587\u4ef6\u7684\u683c\u5f0f\n\/\/        $info-&gt;getSize()&gt;10000000 \/\/\u5224\u65ad\u56fe\u7247\u6587\u4ef6\u7684\u683c\u5f0f\n            if($info){\n                $image_src = '\/public\/uploads\/'.$info-&gt;getSaveName();\n                return $image_src;\n            }else{\n                return '0';\n            }\n        }else{\n            return '0';\n        }\n    }\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u4f7f\u7528summernote\u7f16\u8f91\u5668 summernote\u662f\u4e00\u4e2a\u5f88\u597d\u7528\u7684\u7f16\u8f91\u5668\uff0c\u7b80\u5355\u5927\u65b9\uff0c\u57fa\u672c\u529f\u80fd\u90fd\u6709\uff0c\u6211\u53ea\u8bb0\u2026 <span class=\"read-more\"><a href=\"http:\/\/rain1024.com\/index.php\/2018\/03\/22\/article114\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,34],"tags":[45,57],"class_list":["post-927","post","type-post","status-publish","format-standard","hentry","category-html","category-php","tag-html","tag-php"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=927"}],"version-history":[{"count":1,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/927\/revisions"}],"predecessor-version":[{"id":1419,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/927\/revisions\/1419"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=927"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}