{"id":17,"date":"2024-03-20T10:50:37","date_gmt":"2024-03-20T02:50:37","guid":{"rendered":"http:\/\/log.d9t3.com\/?p=17"},"modified":"2024-03-20T10:52:17","modified_gmt":"2024-03-20T02:52:17","slug":"php-kindeditor%e5%9b%be%e7%89%87%e4%b8%8a%e4%bc%a0%e5%88%b0%e9%98%bf%e9%87%8coss","status":"publish","type":"post","link":"https:\/\/log.d9t3.com\/?p=17","title":{"rendered":"php kindeditor\u56fe\u7247\u4e0a\u4f20\u5230\u963f\u91ccOSS"},"content":{"rendered":"\n<p>upload_json.php\u6539\u52a8\u5982\u4e0b:<\/p>\n\n\n\n<p>\/\/\u5f15\u5165\u963f\u91cc\u81ea\u52a8\u52a0\u8f7d\u6587\u4ef6<\/p>\n\n\n\n<p>require_once &#8216;..\/..\/..\/..\/..\/vendor\/aliyun\/autoload.php&#8217;;\/\/\u6839\u636e\u4f60\u7684\u5b9e\u9645\u5730\u5740<br>use OSS\\Http\\RequestCore;<br>use OSS\\OssClient;<br>use OSS\\Core\\OssException;<br>$accessKeyId = &#8220;&#8221;;\/\/\u53bb\u963f\u91cc\u4e91\u540e\u53f0\u83b7\u53d6\u79d8\u94a5<br>$accessKeySecret = &#8220;&#8221;;\/\/\u53bb\u963f\u91cc\u4e91\u540e\u53f0\u83b7\u53d6\u79d8\u94a5<br>$endpoint = &#8220;oss-cn-shenzhen.aliyuncs.com&#8221;;\/\/\u4f60\u7684\u963f\u91cc\u4e91OSS\u5730\u5740<br>$urls = &#8216;http:\/\/XXXX.oss-cn-shenzhen.aliyuncs.com\/&#8217;;\/\/\u7ed1\u5b9aOSS\u7684URL\uff0c\u524d\u9762\u8981\u52a0http<br>$php_path = dirname(<strong>FILE<\/strong>) . &#8216;\/&#8217;;<br>\/\/$php_url = dirname($_SERVER[&#8216;PHP_SELF&#8217;]) . &#8216;\/&#8217;; \/\/\u5c06\u6b64\u6761\u6ce8\u91ca\u6389<\/p>\n\n\n\n<p>\/\/\u4e0a\u4f20\u7684\u6587\u4ef6\u7684\u672c\u5730\u4e34\u65f6\u4fdd\u5b58\u76ee\u5f55\u8def\u5f84<br>\/\/$save_path = $php_path . &#8216;..\/attached\/&#8217;; \/\/\u5c06\u6b64\u6761\u6ce8\u91ca\u6389<br>$save_path = &#8216;.\/tmp&#8217;; \/\/\u4e0a\u4f20\u6587\u4ef6\u4e34\u65f6\u5b58\u653e<\/p>\n\n\n\n<p>\/\/\u6587\u4ef6\u4fdd\u5b58\u76ee\u5f55URL<br>\/\/$save_url = $php_url . &#8216;..\/attached\/&#8217;; \/\/\u5c06\u6b64\u6761\u6ce8\u91ca\u6389<br>$save_url = &#8216;\/attachs\/&#8217;;<br>\/\/\u627e\u5230\u5224\u65ad\u5f53\u6709\u6587\u4ef6\u4e0a\u4f20\u65f6\u7684if\u8bed\u53e5<\/p>\n\n\n\n<p>\/\/\u65b0\u6587\u4ef6\u540d<br>$new_file_name = date(&#8220;YmdHis&#8221;) . &#8216;_&#8217; . rand(10000, 99999) . &#8216;.&#8217; . $file_ext;<br>\/\/\u79fb\u52a8\u6587\u4ef6<br>$file_path = $save_path . $new_file_name;<br>if (move_uploaded_file($tmp_name, $file_path) === false) {<br>alert(&#8220;\u4e0a\u4f20\u6587\u4ef6\u5931\u8d25\u3002&#8221;);<br>}<br>\/\/@chmod($file_path, 0644);<br>\/\/\u5728\u4e0b\u9762\u5c06\u6587\u4ef6\u4f20\u5230\u963f\u91ccoss<br>$ymd = date(&#8220;Ymd&#8221;);<br>$bucket= &#8220;&#8221;;\/\/oss\u4e2d\u7684\u6587\u4ef6\u4e0a\u4f20\u7a7a\u95f4<br>$object = &#8220;attachs\/&#8221;.$dir_name.&#8221;\/&#8221;.$ymd.&#8221;\/&#8221;.$new_file_name;\/\/\u4e0a\u4f20\u5230\u963f\u91cc\u4e91OSS\u60f3\u8981\u4fdd\u5b58\u6587\u4ef6\u7684\u540d\u79f0<br>$content = $file_path;\/\/\u6587\u4ef6\u8def\u5f84\uff0c\u5fc5\u987b\u662f\u672c\u5730\u7684,\u5728tmp\u6587\u4ef6\u5939\u5e95\u4e0b\u3002<br>$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);<br>try {<br>$ossClient-&gt;uploadFile($bucket, $object, $content);<br>} catch (OssException $e) {<br>print $e-&gt;getMessage();<br>}<\/p>\n\n\n\n<p>\/\/\u6e05\u7a7a\u672c\u5730\u7684\u5b58\u50a8\u6587\u4ef6\u53ca\u76ee\u5f55<br>unlink($file_path);<br>rmdir(&#8220;.\/tmp\/&#8221;.$dir_name.&#8221;\/&#8221;.$ymd);<br>\/\/rmdir(&#8220;.\/tmp\/&#8221;.$dir_name);<\/p>\n\n\n\n<p>\/\/\u4e0a\u4f20\u6210\u529f\u4e4b\u540e\u8fd4\u56de\u963f\u91cc\u4e91OSS\u7684URL<br>$file_url = $urls . $save_url . $new_file_name;<\/p>\n\n\n\n<p>header(&#8216;Content-type: text\/html; charset=UTF-8&#8217;);<br>$json = new Services_JSON();<br>echo $json-&gt;encode(array(&#8216;error&#8217; =&gt; 0, &#8216;url&#8217; =&gt; $file_url));<br>exit;<\/p>\n\n\n\n<p>\/\/file_manager_json.php \u6539\u52a8\u5982\u4e0b<\/p>\n\n\n\n<p>\/\/\u7ed1\u5b9aOSS\u7684URL\uff0c\u524d\u9762\u8981\u52a0http\uff0c\u6bd4\u5982 http:\/\/www.yoursite.com\/<br>$urls = &#8216;http:\/\/XXXX.oss-cn-shenzhen.aliyuncs.com\/&#8217;; \/\/XXXX\u4e3a\u586b\u5199\u81ea\u5df1\u7684\u963f\u91ccOSS\u57df\u540d<br>$save_url = &#8216;\/attachs\/&#8217;;<\/p>\n\n\n\n<p>\/\/\u6839\u76ee\u5f55\u8def\u5f84\uff0c\u53ef\u4ee5\u6307\u5b9a\u7edd\u5bf9\u8def\u5f84\uff0c\u6bd4\u5982 \/var\/www\/attached\/<br>\/\/$root_path = $php_path . &#8216;..\/attached\/&#8217;;<br>$root_path = &#8216;.\/tmp\/&#8217;;<br>\/\/\u6839\u76ee\u5f55URL\uff0c\u53ef\u4ee5\u6307\u5b9a\u7edd\u5bf9\u8def\u5f84\uff0c\u6bd4\u5982 http:\/\/www.yoursite.com\/attached\/<br>\/\/$root_url = $php_url . &#8216;..\/attached\/&#8217;;<br>$root_url = $urls . $save_url;\/\/\u963f\u91cc\u4e91OSS\u7684URL\/attached\/<br>\/\/\u4e0a\u4f20\u6210\u529f\u65f6 kindeditor \u5730\u5740\u53d8\u4e3a\u963f\u91ccoss\u5730\u5740<br><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"30\" class=\"wp-image-18\" style=\"width: 686px;\" src=\"http:\/\/log.d9t3.com\/wp-content\/uploads\/2024\/03\/20180807120202684.png\" alt=\"\" srcset=\"https:\/\/log.d9t3.com\/wp-content\/uploads\/2024\/03\/20180807120202684.png 686w, https:\/\/log.d9t3.com\/wp-content\/uploads\/2024\/03\/20180807120202684-300x13.png 300w\" sizes=\"(max-width: 686px) 100vw, 686px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>upload_json.php\u6539\u52a8\u5982\u4e0b: \/\/\u5f15\u5165\u963f\u91cc\u81ea\u52a8\u52a0\u8f7d\u6587\u4ef6 require_once &#8216;.<\/p>\n<div class=\"more-link\">\n\t\t\t\t <a href=\"https:\/\/log.d9t3.com\/?p=17\" class=\"link-btn theme-btn\"><span>Read More <\/span> <i class=\"fa fa-caret-right\"><\/i><\/a>\n\t\t\t<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/log.d9t3.com\/index.php?rest_route=\/wp\/v2\/posts\/17"}],"collection":[{"href":"https:\/\/log.d9t3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/log.d9t3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/log.d9t3.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/log.d9t3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17"}],"version-history":[{"count":2,"href":"https:\/\/log.d9t3.com\/index.php?rest_route=\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":21,"href":"https:\/\/log.d9t3.com\/index.php?rest_route=\/wp\/v2\/posts\/17\/revisions\/21"}],"wp:attachment":[{"href":"https:\/\/log.d9t3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/log.d9t3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/log.d9t3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}