{"id":23046,"date":"2024-11-21T08:55:28","date_gmt":"2024-11-21T00:55:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23046\/"},"modified":"2024-11-21T08:55:28","modified_gmt":"2024-11-21T00:55:28","slug":"thinkphp%e5%ae%9e%e7%8e%b0%e8%a1%a8%e5%8d%95%e4%b8%8a%e4%bc%a0%e9%99%84%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23046\/","title":{"rendered":"thinkphp\u5b9e\u73b0\u8868\u5355\u4e0a\u4f20\u9644\u4ef6"},"content":{"rendered":"<p>\u5728web\u5f00\u53d1\u4e2d\uff0c\u8868\u5355\u7684\u4e0a\u4f20\u9644\u4ef6\u529f\u80fd\u662f\u975e\u5e38\u5e38\u89c1\u7684\uff0c\u8fd9\u4e2a\u529f\u80fd\u80fd\u591f\u8ba9\u7528\u6237\u65b9\u4fbf\u5730\u4e0a\u4f20\u81ea\u5df1\u6240\u9700\u8981\u7684\u6587\u4ef6\uff0c\u6bd4\u5982\u56fe\u7247\u3001\u6587\u6863\u3001\u97f3\u9891\u7b49\u7b49\u3002\u800c\u5728php\u8bed\u8a00\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528thinkphp\u6846\u67b6\u6765\u5b9e\u73b0\u8868\u5355\u4e0a\u4f20\u9644\u4ef6\u7684\u529f\u80fd\u3002\u4e0b\u9762\u6211\u4eec\u6765\u4e00\u6b65\u4e00\u6b65\u5730\u5b66\u4e60\u5982\u4f55\u4f7f\u7528thinkphp\u5b9e\u73b0\u8868\u5355\u4e0a\u4f20\u9644\u4ef6\u3002<\/p>\n<p>\u4e00\u3001\u73af\u5883\u51c6\u5907<\/p>\n<p>\u5728\u4f7f\u7528thinkphp\u6846\u67b6\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5148\u642d\u5efa\u4e00\u4e2a\u9002\u5f53\u7684\u8fd0\u884c\u73af\u5883\u3002\u5177\u4f53\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u5b89\u88c5php\u73af\u5883<\/li>\n<li>\u5b89\u88c5composer<\/li>\n<li>\u65b0\u5efa\u4e00\u4e2athinkphp\u9879\u76ee<\/li>\n<li>\u914d\u7f6e\u6570\u636e\u5e93\u548c\u8def\u7531<\/li>\n<li>\u5b89\u88c5\u5fc5\u8981\u7684\u6269\u5c55\u5e93<\/li>\n<\/ol>\n<p>\u4e8c\u3001\u521b\u5efa\u4e0a\u4f20\u8868\u5355<\/p>\n<p>\u5728thinkphp\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528form\u8868\u5355\u751f\u6210\u5668\u6765\u5feb\u901f\u751f\u6210\u4e00\u4e2a\u4e0a\u4f20\u8868\u5355\u3002\u5177\u4f53\u5b9e\u73b0\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aupload\u7684\u63a7\u5236\u5668\uff0c\u5728\u8be5\u63a7\u5236\u5668\u4e2d\uff0c\u6dfb\u52a0\u4e00\u4e2aindex\u65b9\u6cd5\u3002<\/li>\n<\/ol>\n<pre>namespace appindexcontroller;\n\nuse thinkController;\n\nclass Upload extends Controller\n{\n    public function index()\n    {\n        return $this-&amp;gt;fetch();\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u5728view\u6587\u4ef6\u5939\u4e2d\u65b0\u5efa\u4e00\u4e2aupload.html\u6587\u4ef6\u3002<\/li>\n<\/ol>\n<pre>\n\n\n    &lt;meta charset=\"UTF-8\"&gt;&lt;title&gt;Upload&lt;\/title&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u4f1a\u751f\u6210\u4e00\u4e2a\u5305\u542b\u6587\u4ef6\u4e0a\u4f20\u529f\u80fd\u7684\u8868\u5355\uff0c\u5176\u4e2dinput\u6807\u7b7e\u7684name\u5c5e\u6027\u4e3afile\uff0c\u5373\u4e0a\u4f20\u6587\u4ef6\u7684\u540d\u79f0\u3002<\/p>\n<p>\u4e09\u3001\u5904\u7406\u4e0a\u4f20\u6587\u4ef6<\/p>\n<p>\u5f53\u7528\u6237\u70b9\u51fb\u4e0a\u4f20\u6309\u94ae\u5e76\u9009\u62e9\u4e86\u4e0a\u4f20\u6587\u4ef6\u540e\uff0c\u6211\u4eec\u5c31\u9700\u8981\u5c06\u4e0a\u4f20\u7684\u6587\u4ef6\u4fdd\u5b58\u5230\u6307\u5b9a\u7684\u4f4d\u7f6e\u3002\u8fd9\u4e2a\u529f\u80fd\u9700\u8981\u5728\u63a7\u5236\u5668\u4e2d\u5b9e\u73b0\uff0c\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u4fee\u6539upload.html\u7684form\u8868\u5355action\u5c5e\u6027\u4e3aupload\/uploadFile\u3002<\/li>\n<\/ol>\n<pre><\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u5728upload\u63a7\u5236\u5668\u4e2d\u6dfb\u52a0uploadFile\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u4f1a\u5c06\u4e0a\u4f20\u6587\u4ef6\u4fdd\u5b58\u5230\u6307\u5b9a\u7684\u4f4d\u7f6e\u5e76\u8fd4\u56de\u4e0a\u4f20\u6587\u4ef6\u7684\u4fe1\u606f\u3002\u7531\u4e8ethinkphp\u6846\u67b6\u81ea\u5e26\u4e86\u6587\u4ef6\u4e0a\u4f20\u7c7b\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8be5\u7c7b\u6765\u5b8c\u6210\u6587\u4ef6\u4e0a\u4f20\u7684\u529f\u80fd\u3002<\/li>\n<\/ol>\n<pre>public function uploadFile()\n{\n    $file = request()-&amp;gt;file('file');\n\n    $info = $file-&amp;gt;move(ROOT_PATH . 'public' . DS . 'uploads');\n\n    if ($info) {\n        return '\u6587\u4ef6\u4e0a\u4f20\u6210\u529f\uff1a' . $info-&amp;gt;getSaveName();\n    } else {\n        return $file-&amp;gt;getError();\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u53ef\u4ee5\u83b7\u53d6\u5230\u4e0a\u4f20\u7684\u6587\u4ef6\u5bf9\u8c61\uff0c\u7136\u540e\u4f7f\u7528\u6587\u4ef6\u4e0a\u4f20\u7c7b\u6765\u4fdd\u5b58\u6587\u4ef6\u5230\u6307\u5b9a\u7684\u4f4d\u7f6e\u3002\u5982\u679c\u4e0a\u4f20\u6210\u529f\uff0c\u5219\u8fd4\u56de\u4e0a\u4f20\u6587\u4ef6\u7684\u4fe1\u606f\uff1b\u5426\u5219\u5c31\u8fd4\u56de\u4e0a\u4f20\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<p>\u5728\u5b8c\u6210\u4ee5\u4e0a\u6b65\u9aa4\u540e\uff0c\u6211\u4eec\u7684\u4e0a\u4f20\u9644\u4ef6\u529f\u80fd\u5c31\u5b8c\u6210\u4e86\u3002\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u4e0a\u4f20\u8868\u5355\u8f7b\u677e\u5730\u4e0a\u4f20\u81ea\u5df1\u7684\u6587\u4ef6\u4e86\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528thinkphp\u6846\u67b6\u6765\u5b9e\u73b0\u4e86\u8868\u5355\u4e0a\u4f20\u9644\u4ef6\u7684\u529f\u80fd\u3002\u8fd9\u4e2a\u5b9e\u73b0\u6b65\u9aa4\u6bd4\u8f83\u7b80\u5355\uff0c\u53ea\u9700\u8981\u6309\u7167\u4e0a\u8ff0\u6b65\u9aa4\u4e00\u6b65\u4e00\u6b65\u5730\u5b8c\u6210\u5373\u53ef\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cthinkphp\u6846\u67b6\u63d0\u4f9b\u4e86\u975e\u5e38\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u7c7b\u5e93\uff0c\u6df1\u5165\u5b66\u4e60thinkphp\u6846\u67b6\u53ef\u4ee5\u8ba9\u6211\u4eec\u5728web\u5f00\u53d1\u4e2d\u66f4\u52a0\u9ad8\u6548\u5730\u5b8c\u6210\u4efb\u52a1\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fthinkphp\u5b9e\u73b0\u8868\u5355\u4e0a\u4f20\u9644\u4ef6\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728web\u5f00\u53d1\u4e2d\uff0c\u8868\u5355\u7684\u4e0a\u4f20\u9644\u4ef6\u529f\u80fd\u662f\u975e\u5e38\u5e38\u89c1\u7684\uff0c\u8fd9\u4e2a\u529f\u80fd\u80fd\u591f\u8ba9\u7528\u6237\u65b9\u4fbf\u5730\u4e0a\u4f20\u81ea\u5df1\u6240\u9700\u8981\u7684\u6587\u4ef6\uff0c\u6bd4\u5982\u56fe\u7247\u3001\u6587\u6863\u3001\u97f3\u9891\u7b49\u7b49\u3002\u800c\u5728php\u8bed\u8a00\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528thinkphp\u6846\u67b6\u6765\u5b9e\u73b0\u8868\u5355\u4e0a\u4f20\u9644\u4ef6\u7684\u529f\u80fd\u3002\u4e0b\u9762\u6211\u4eec\u6765\u4e00\u6b65\u4e00\u6b65\u5730\u5b66\u4e60\u5982\u4f55\u4f7f\u7528thinkphp\u5b9e\u73b0\u8868\u5355\u4e0a\u4f20\u9644\u4ef6\u3002 \u4e00\u3001\u73af\u5883\u51c6\u5907 \u5728\u4f7f\u7528thinkphp\u6846\u67b6\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5148\u642d\u5efa\u4e00\u4e2a\u9002\u5f53\u7684\u8fd0\u884c\u73af\u5883\u3002\u5177\u4f53\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a \u5b89\u88c5php\u73af\u5883 \u5b89\u88c5composer \u65b0\u5efa\u4e00\u4e2athinkphp\u9879\u76ee \u914d\u7f6e\u6570\u636e\u5e93\u548c\u8def\u7531 \u5b89\u88c5\u5fc5\u8981\u7684\u6269\u5c55\u5e93 \u4e8c\u3001\u521b\u5efa\u4e0a\u4f20\u8868\u5355 \u5728thinkphp\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528form\u8868\u5355\u751f\u6210\u5668\u6765\u5feb\u901f\u751f\u6210\u4e00\u4e2a\u4e0a\u4f20\u8868\u5355\u3002\u5177\u4f53\u5b9e\u73b0\u6b65\u9aa4\u5982\u4e0b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u521b\u5efa\u4e00\u4e2a\u540d\u4e3aupload\u7684\u63a7\u5236\u5668\uff0c\u5728\u8be5\u63a7\u5236\u5668\u4e2d\uff0c\u6dfb\u52a0\u4e00\u4e2aindex\u65b9\u6cd5\u3002 namespace appindexcontroller; use thinkController; class Upload extends Controller { public function index() { return $this-&amp;gt;fetch(); } } \u767b\u5f55\u540e\u590d\u5236 \u5728view\u6587\u4ef6\u5939\u4e2d\u65b0\u5efa\u4e00\u4e2aupload.html\u6587\u4ef6\u3002 &lt;meta charset=&#8221;UTF-8&#8243;&gt;&lt;title&gt;Upload&lt;\/title&gt; \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u4ee3\u7801\u4f1a\u751f\u6210\u4e00\u4e2a\u5305\u542b\u6587\u4ef6\u4e0a\u4f20\u529f\u80fd\u7684\u8868\u5355\uff0c\u5176\u4e2dinput\u6807\u7b7e\u7684name\u5c5e\u6027\u4e3afile\uff0c\u5373\u4e0a\u4f20\u6587\u4ef6\u7684\u540d\u79f0\u3002 \u4e09\u3001\u5904\u7406\u4e0a\u4f20\u6587\u4ef6 \u5f53\u7528\u6237\u70b9\u51fb\u4e0a\u4f20\u6309\u94ae\u5e76\u9009\u62e9\u4e86\u4e0a\u4f20\u6587\u4ef6\u540e\uff0c\u6211\u4eec\u5c31\u9700\u8981\u5c06\u4e0a\u4f20\u7684\u6587\u4ef6\u4fdd\u5b58\u5230\u6307\u5b9a\u7684\u4f4d\u7f6e\u3002\u8fd9\u4e2a\u529f\u80fd\u9700\u8981\u5728\u63a7\u5236\u5668\u4e2d\u5b9e\u73b0\uff0c\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a \u4fee\u6539upload.html\u7684form\u8868\u5355action\u5c5e\u6027\u4e3aupload\/uploadFile\u3002 \u767b\u5f55\u540e\u590d\u5236 \u5728upload\u63a7\u5236\u5668\u4e2d\u6dfb\u52a0uploadFile\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u4f1a\u5c06\u4e0a\u4f20\u6587\u4ef6\u4fdd\u5b58\u5230\u6307\u5b9a\u7684\u4f4d\u7f6e\u5e76\u8fd4\u56de\u4e0a\u4f20\u6587\u4ef6\u7684\u4fe1\u606f\u3002\u7531\u4e8ethinkphp\u6846\u67b6\u81ea\u5e26\u4e86\u6587\u4ef6\u4e0a\u4f20\u7c7b\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8be5\u7c7b\u6765\u5b8c\u6210\u6587\u4ef6\u4e0a\u4f20\u7684\u529f\u80fd\u3002 public function uploadFile() { $file = request()-&amp;gt;file(&#8216;file&#8217;); $info = $file-&amp;gt;move(ROOT_PATH . &#8216;public&#8217; . DS . [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-23046","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=23046"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23046\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}