{"id":23031,"date":"2024-11-21T08:58:50","date_gmt":"2024-11-21T00:58:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23031\/"},"modified":"2024-11-21T08:58:50","modified_gmt":"2024-11-21T00:58:50","slug":"laravel-%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0%e5%a4%b1%e8%b4%a5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23031\/","title":{"rendered":"laravel \u6587\u4ef6\u4e0a\u4f20\u5931\u8d25"},"content":{"rendered":"<p>\u5728\u4f7f\u7528 laravel \u5f00\u53d1 web \u5e94\u7528\u65f6\uff0c\u5e38\u5e38\u9700\u8981\u8fdb\u884c\u6587\u4ef6\u4e0a\u4f20\u3002\u4f46\u662f\uff0c\u6709\u65f6\u4e0a\u4f20\u6587\u4ef6\u4f1a\u5931\u8d25\uff0c\u5bfc\u81f4\u5f00\u53d1\u8fc7\u7a0b\u53d8\u5f97\u56f0\u96be\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u7684\u6587\u4ef6\u4e0a\u4f20\u5931\u8d25\u7684\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n<ol>\n<li>\u4e0a\u4f20\u6587\u4ef6\u8d85\u51fa\u4e86 php.ini \u4e2d\u7684\u914d\u7f6e<\/li>\n<\/ol>\n<p>\u5728 php.ini \u6587\u4ef6\u4e2d\uff0c\u6709\u4e00\u4e9b\u914d\u7f6e\u4e0e\u6587\u4ef6\u4e0a\u4f20\u6709\u5173\uff0c\u4f8b\u5982 upload_max_filesize \u548c post_max_size\u3002\u5982\u679c\u4e0a\u4f20\u7684\u6587\u4ef6\u5927\u5c0f\u8d85\u8fc7\u4e86\u8fd9\u4e9b\u914d\u7f6e\u6240\u5141\u8bb8\u7684\u8303\u56f4\uff0c\u6587\u4ef6\u4e0a\u4f20\u5c31\u4f1a\u5931\u8d25\u3002\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u4fee\u6539 php.ini \u6587\u4ef6\u4e2d\u76f8\u5e94\u7684\u914d\u7f6e\uff0c\u5c06\u5176\u8c03\u5927\u5230\u4e0a\u4f20\u7684\u6587\u4ef6\u5927\u5c0f\u8303\u56f4\u5185\u5373\u53ef\u3002\u4fee\u6539\u540e\u8bb0\u5f97\u91cd\u542f Apache \u6216\u5176\u4ed6 web \u670d\u52a1\u5668\uff0c\u5426\u5219\u4fee\u6539\u4e0d\u4f1a\u751f\u6548\u3002<\/p>\n<ol>\n<li>\u8868\u5355\u6ca1\u6709\u8bbe\u7f6e\u6b63\u786e\u7684 enctype \u5c5e\u6027<\/li>\n<\/ol>\n<p>\u5f53\u4f7f\u7528\u8868\u5355\u4e0a\u4f20\u6587\u4ef6\u65f6\uff0c\u8981\u8bb0\u5f97\u8bbe\u7f6e\u8868\u5355\u7684 enctype \u5c5e\u6027\u4e3a &#8220;multipart\/form-data&#8221;\u3002\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e\uff0c\u6587\u4ef6\u4e0a\u4f20\u4e5f\u4f1a\u5931\u8d25\u3002\u5728 Laravel \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 Blade \u6a21\u677f\u5f15\u64ce\u7684 form \u8f85\u52a9\u51fd\u6570\u8bbe\u7f6e\u8868\u5355\u7684 enctype \u5c5e\u6027\uff1a<\/p>\n<pre>{!! Form::open(['url' =&amp;gt; '\/upload', 'method' =&amp;gt; 'POST', 'files' =&amp;gt; true, 'enctype' =&amp;gt; 'multipart\/form-data']) !!}\n\/\/ \u8868\u5355\u5143\u7d20\n{!! Form::close() !!}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc\u8fd8\u9700\u8981\u8bbe\u7f6e &#8216;files&#8217; =&gt; true\uff0c\u8868\u793a\u8868\u5355\u4e2d\u5305\u542b\u6587\u4ef6\u4e0a\u4f20\u3002<\/p>\n<ol>\n<li>\u76ee\u6807\u6587\u4ef6\u5939\u6ca1\u6709\u6b63\u786e\u8bbe\u7f6e\u6743\u9650<\/li>\n<\/ol>\n<p>\u5f53\u4e0a\u4f20\u6587\u4ef6\u65f6\uff0cLaravel \u4f1a\u5c06\u6587\u4ef6\u4fdd\u5b58\u5230\u6307\u5b9a\u7684\u76ee\u6807\u6587\u4ef6\u5939\u4e2d\u3002\u5982\u679c\u8be5\u76ee\u5f55\u6ca1\u6709\u5199\u5165\u6743\u9650\uff0c\u6587\u4ef6\u4e0a\u4f20\u5c06\u5931\u8d25\u3002\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u4e3a\u76ee\u6807\u6587\u4ef6\u5939\u8bbe\u7f6e\u6b63\u786e\u7684\u6743\u9650\uff1a<\/p>\n<pre>chmod -R 777 \/path\/to\/upload\/folder<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc\u7ed9\u76ee\u6807\u6587\u4ef6\u5939\u8d4b\u4e88\u4e86 777 \u7684\u6743\u9650\uff0c\u8fd9\u610f\u5473\u7740\u5168\u90e8\u7528\u6237\u90fd\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u8bfb\u5199\u64cd\u4f5c\uff0c\u53ef\u80fd\u5b58\u5728\u5b89\u5168\u98ce\u9669\uff0c\u8bf7\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8bbe\u7f6e\u5408\u7406\u7684\u6743\u9650\u3002<\/p>\n<ol>\n<li>\u6587\u4ef6\u4e0a\u4f20\u88ab\u670d\u52a1\u5668\u9650\u5236<\/li>\n<\/ol>\n<p>\u6709\u4e9b web \u670d\u52a1\u5668\u4f1a\u9650\u5236\u6587\u4ef6\u4e0a\u4f20\uff0c\u4f8b\u5982 Nginx \u9ed8\u8ba4\u9650\u5236\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u4e3a 1MB\u3002\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d\u7684 client_max_body_size \u6765\u8c03\u6574\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u9650\u5236\uff1a<\/p>\n<pre>client_max_body_size 20M;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc\u5c06\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u9650\u5236\u8bbe\u7f6e\u4e3a 20MB\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<ol>\n<li>\u6587\u4ef6\u4e0a\u4f20\u88ab\u8ba4\u4e3a\u662f\u6076\u610f\u653b\u51fb<\/li>\n<\/ol>\n<p>\u6709\u4e9b web \u5e94\u7528\u7684\u670d\u52a1\u5668\u4f1a\u5bf9\u4e0a\u4f20\u7684\u6587\u4ef6\u8fdb\u884c\u5b89\u5168\u68c0\u67e5\uff0c\u5982\u679c\u8ba4\u4e3a\u4e0a\u4f20\u7684\u6587\u4ef6\u53ef\u80fd\u662f\u6076\u610f\u7684\uff0c\u4e0a\u4f20\u5c31\u4f1a\u5931\u8d25\u3002\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u6839\u636e\u670d\u52a1\u5668\u7684\u65e5\u5fd7\u5206\u6790\u4e0a\u4f20\u5931\u8d25\u7684\u539f\u56e0\uff0c\u67e5\u627e\u4e0a\u4f20\u6587\u4ef6\u4e2d\u53ef\u80fd\u5b58\u5728\u7684\u5371\u9669\u56e0\u7d20\uff0c\u4f8b\u5982\u75c5\u6bd2\u3001\u975e\u6cd5\u4ee3\u7801\u3001\u6728\u9a6c\u7b49\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u6587\u4ef6\u4e0a\u4f20\u5931\u8d25\u6709\u591a\u79cd\u539f\u56e0\uff0c\u5e76\u4e0d\u662f\u6240\u6709\u60c5\u51b5\u90fd\u53ef\u4ee5\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\u89e3\u51b3\u3002\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bb0\u5f55\u65e5\u5fd7\u548c\u8c03\u8bd5\u6765\u67e5\u627e\u6587\u4ef6\u4e0a\u4f20\u5931\u8d25\u7684\u539f\u56e0\uff0c\u5e76\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u91c7\u53d6\u76f8\u5e94\u7684\u89e3\u51b3\u65b9\u6cd5\u3002\u5982\u679c\u4f60\u8fd8\u9047\u5230\u5176\u4ed6\u6587\u4ef6\u4e0a\u4f20\u5931\u8d25\u7684\u95ee\u9898\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u7559\u8a00\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u63a2\u8ba8\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662flaravel \u6587\u4ef6\u4e0a\u4f20\u5931\u8d25\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>\u5728\u4f7f\u7528 laravel \u5f00\u53d1 web \u5e94\u7528\u65f6\uff0c\u5e38\u5e38\u9700\u8981\u8fdb\u884c\u6587\u4ef6\u4e0a\u4f20\u3002\u4f46\u662f\uff0c\u6709\u65f6\u4e0a\u4f20\u6587\u4ef6\u4f1a\u5931\u8d25\uff0c\u5bfc\u81f4\u5f00\u53d1\u8fc7\u7a0b\u53d8\u5f97\u56f0\u96be\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u7684\u6587\u4ef6\u4e0a\u4f20\u5931\u8d25\u7684\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6cd5\u3002 \u4e0a\u4f20\u6587\u4ef6\u8d85\u51fa\u4e86 php.ini \u4e2d\u7684\u914d\u7f6e \u5728 php.ini \u6587\u4ef6\u4e2d\uff0c\u6709\u4e00\u4e9b\u914d\u7f6e\u4e0e\u6587\u4ef6\u4e0a\u4f20\u6709\u5173\uff0c\u4f8b\u5982 upload_max_filesize \u548c post_max_size\u3002\u5982\u679c\u4e0a\u4f20\u7684\u6587\u4ef6\u5927\u5c0f\u8d85\u8fc7\u4e86\u8fd9\u4e9b\u914d\u7f6e\u6240\u5141\u8bb8\u7684\u8303\u56f4\uff0c\u6587\u4ef6\u4e0a\u4f20\u5c31\u4f1a\u5931\u8d25\u3002\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u4fee\u6539 php.ini \u6587\u4ef6\u4e2d\u76f8\u5e94\u7684\u914d\u7f6e\uff0c\u5c06\u5176\u8c03\u5927\u5230\u4e0a\u4f20\u7684\u6587\u4ef6\u5927\u5c0f\u8303\u56f4\u5185\u5373\u53ef\u3002\u4fee\u6539\u540e\u8bb0\u5f97\u91cd\u542f Apache \u6216\u5176\u4ed6 web \u670d\u52a1\u5668\uff0c\u5426\u5219\u4fee\u6539\u4e0d\u4f1a\u751f\u6548\u3002 \u8868\u5355\u6ca1\u6709\u8bbe\u7f6e\u6b63\u786e\u7684 enctype \u5c5e\u6027 \u5f53\u4f7f\u7528\u8868\u5355\u4e0a\u4f20\u6587\u4ef6\u65f6\uff0c\u8981\u8bb0\u5f97\u8bbe\u7f6e\u8868\u5355\u7684 enctype \u5c5e\u6027\u4e3a &#8220;multipart\/form-data&#8221;\u3002\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e\uff0c\u6587\u4ef6\u4e0a\u4f20\u4e5f\u4f1a\u5931\u8d25\u3002\u5728 Laravel \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 Blade \u6a21\u677f\u5f15\u64ce\u7684 form \u8f85\u52a9\u51fd\u6570\u8bbe\u7f6e\u8868\u5355\u7684 enctype \u5c5e\u6027\uff1a {!! Form::open([&#8216;url&#8217; =&amp;gt; &#8216;\/upload&#8217;, &#8216;method&#8217; =&amp;gt; &#8216;POST&#8217;, &#8216;files&#8217; =&amp;gt; true, &#8216;enctype&#8217; =&amp;gt; &#8216;multipart\/form-data&#8217;]) !!} \/\/ \u8868\u5355\u5143\u7d20 {!! Form::close() !!} \u767b\u5f55\u540e\u590d\u5236 [&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-23031","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23031","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=23031"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23031\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}