{"id":243,"date":"2009-02-28T21:24:00","date_gmt":"2009-02-28T01:24:00","guid":{"rendered":""},"modified":"2013-11-29T14:21:22","modified_gmt":"2013-11-29T06:21:22","slug":"php%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e5%85%a8%e6%94%bb%e7%95%a5","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/243.html","title":{"rendered":"php\u4e0a\u4f20\u6587\u4ef6\u5168\u653b\u7565"},"content":{"rendered":"<p>1.\u4e0a\u4f20\u8868\u5355<\/p>\n<p>upload.html<\/p>\n<p>\u7a0b\u5e8f\u4ee3\u7801<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;form enctype=&quot;multipart\/form-data&quot; action=&quot;upload.php&quot; method=&quot;post&quot;&gt;\r\n&lt;input type=&quot;hidden&quot; name=&quot;max_file_size&quot; value=&quot;100000&quot;&gt;\r\n&lt;input name=&quot;userfile&quot; type=&quot;file&quot;&gt;\r\n&lt;input type=&quot;submit&quot; value=&quot;\u4e0a\u4f20\u6587\u4ef6&quot;&gt;\r\n&lt;\/form&gt;\r\n<\/pre>\n<p>1.\u6ce8\u610f<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;form enctype=&quot;multipart\/form-data&quot;\u2026\u2026&gt;\r\n<\/pre>\n<p>\u8fd9\u662f\u4e00\u4e2a\u6807\u7b7e\uff0c\u6211\u4eec\u8981\u5b9e\u73b0\u6587\u4ef6\u7684\u4e0a\u4f20\uff0c\u5fc5\u987b\u6307\u5b9a\u4e3amultipart\/form-data\uff0c\u5426\u5219\u670d\u52a1\u5668\u5c06\u4e0d\u77e5\u9053\u8981\u5e72\u4ec0\u4e48\u3002<\/p>\n<p>2.\u503c\u5f97\u6ce8\u610f\u7684\u662f\u6587\u4ef6upload.html\u4e2d\u8868\u5355\u9009\u9879 MAX_FILE_SIZE \u7684\u9690\u85cf\u503c\u57df\uff0c\u901a\u8fc7\u8bbe\u7f6e\u5176Value(\u503c)\u53ef\u4ee5\u9650\u5236\u4e0a\u8f7d\u6587\u4ef6\u7684\u5927\u5c0f\u3002<\/p>\n<p>3.MAX_FILE_SIZE \u7684\u503c\u53ea\u662f\u5bf9\u6d4f\u89c8\u5668\u7684\u4e00\u4e2a\u5efa\u8bae\uff0c\u5b9e\u9645\u4e0a\u5b83\u53ef\u4ee5\u88ab\u7b80\u5355\u7684\u7ed5\u8fc7\u3002\u56e0\u6b64\u4e0d\u8981\u628a\u5bf9\u6d4f\u89c8\u5668\u7684\u9650\u5236\u5bc4\u5e0c\u671b\u4e8e\u8be5\u503c\u3002\u5b9e\u9645\u4e0a\uff0cPHP \u8bbe\u7f6e\u4e2d\u7684\u4e0a\u4f20\u6587\u4ef6\u6700\u5927\u503c\uff0c\u662f\u4e0d\u4f1a\u5931\u6548\u7684\u3002\u4f46\u662f\u6700\u597d\u8fd8\u662f\u5728\u8868\u5355\u4e2d\u52a0\u4e0a MAX_FILE_SIZE\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u907f\u514d\u7528\u6237\u5728\u82b1\u65f6\u95f4\u7b49\u5f85\u4e0a\u4f20\u5927\u6587\u4ef6\u4e4b\u540e\u624d\u53d1\u73b0\u8be5\u6587\u4ef6\u592a\u5927\u4e86\u7684\u9ebb\u70e6\u3002<\/p>\n<p>PHP\u4e0a\u4f20\u6587\u4ef6\u6d89\u53ca\u5230\u7684\u53c2\u6570<\/p>\n<p>\u7a0b\u5e8f\u4ee3\u7801<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$f=&amp;$HTTP_POST_FILES&#x5B;'Myfile'];\r\n$dest_dir=\u2019uploads\u2019;\/\/\u8bbe\u5b9a\u4e0a\u4f20\u76ee\u5f55\r\n$dest=$dest_dir.\u2019\/\u2019.date(&quot;ymd&quot;).&quot;_&quot;.$f&#x5B;'name'];\/\/\u8bbe\u7f6e\u6587\u4ef6\u540d\u4e3a\u65e5\u671f\u52a0\u4e0a\u6587\u4ef6\u540d\u907f\u514d\u91cd\u590d\r\n$r=move_uploaded_file($f&#x5B;'tmp_name'],$dest);\r\nchmod($dest, 0755);\/\/\u8bbe\u5b9a\u4e0a\u4f20\u7684\u6587\u4ef6\u7684\u5c5e\u6027\r\n<\/pre>\n<p>\u6216\u8005<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?copy($_FILES&#x5B;MyFile]&#x5B;tmp_name],$_FILES&#x5B;MyFile]&#x5B;name]);?&gt;\r\n<\/pre>\n<p>\u4ee5\u4e0a\u8303\u4f8b\u4e2d $_FILES \u6570\u7ec4\u7684\u5185\u5bb9\u5982\u4e0b\u6240\u793a\u3002\u6211\u4eec\u5047\u8bbe\u6587\u4ef6\u4e0a\u4f20\u5b57\u6bb5\u7684\u540d\u79f0\u4e3a userfile\uff08\u540d\u79f0\u53ef\u968f\u610f\u547d\u540d\uff09<\/p>\n<p>$_FILES[&#8216;userfile&#8217;][&#8216;name&#8217;] \u5ba2\u6237\u7aef\u673a\u5668\u6587\u4ef6\u7684\u539f\u540d\u79f0\u3002<br \/>\n$_FILES[&#8216;userfile&#8217;][&#8216;type&#8217;] \u6587\u4ef6\u7684 MIME \u7c7b\u578b\uff0c\u9700\u8981\u6d4f\u89c8\u5668\u63d0\u4f9b\u8be5\u4fe1\u606f\u7684\u652f\u6301\uff0c\u4f8b\u5982\u201cimage\/gif\u201d\u3002<br \/>\n$_FILES[&#8216;userfile&#8217;][&#8216;size&#8217;] \u5df2\u4e0a\u4f20\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u5355\u4f4d\u4e3a\u5b57\u8282\u3002<br \/>\n$_FILES[&#8216;userfile&#8217;][&#8216;tmp_name&#8217;] \u6587\u4ef6\u88ab\u4e0a\u4f20\u540e\u5728\u670d\u52a1\u7aef\u50a8\u5b58\u7684\u4e34\u65f6\u6587\u4ef6\u540d\u3002<br \/>\n$_FILES[&#8216;userfile&#8217;][&#8216;error&#8217;] \u548c\u8be5\u6587\u4ef6\u4e0a\u4f20\u76f8\u5173\u7684\u9519\u8bef\u4ee3\u7801<br \/>\n\u503c\uff1a0; \u6ca1\u6709\u9519\u8bef\u53d1\u751f\uff0c\u6587\u4ef6\u4e0a\u4f20\u6210\u529f\u3002<br \/>\n\u503c\uff1a1; \u4e0a\u4f20\u7684\u6587\u4ef6\u8d85\u8fc7\u4e86 php.ini \u4e2d upload_max_filesize \u9009\u9879\u9650\u5236\u7684\u503c\u3002<br \/>\n\u503c\uff1a2; \u4e0a\u4f20\u6587\u4ef6\u7684\u5927\u5c0f\u8d85\u8fc7\u4e86 HTML \u8868\u5355\u4e2d MAX_FILE_SIZE \u9009\u9879\u6307\u5b9a\u7684\u503c\u3002<br \/>\n\u503c\uff1a3; \u6587\u4ef6\u53ea\u6709\u90e8\u5206\u88ab\u4e0a\u4f20\u3002<br \/>\n\u503c\uff1a4; \u6ca1\u6709\u6587\u4ef6\u88ab\u4e0a\u4f20\u3002<\/p>\n<p>PHP\u9ed8\u8ba4\u7684\u4e0a\u4f20\u9650\u5b9a\u662f\u6700\u59272M\uff0c\u60f3\u4e0a\u4f20\u8d85\u8fc7\u6b64\u8bbe\u5b9a\u7684\u6587\u4ef6\uff0c\u9700\u8981\u8c03\u6574PHP\u3001apache\u7b49\u7684\u4e00\u4e9b\u53c2\u6570. \u4e0b\u9762\uff0c\u6211\u4eec\u7b80\u8981\u4ecb\u7ecd\u4e00\u4e0bPHP\u6587\u4ef6\u4e0a\u4f20\u6d89\u53ca\u5230\u7684\u4e00\u4e9b\u53c2\u6570\uff1a<\/p>\n<p>file_uploads<br \/>\n\u662f\u5426\u5141\u8bb8\u901a\u8fc7HTTP\u4e0a\u4f20\u6587\u4ef6\u7684\u5f00\u5173\uff0c\u9ed8\u8ba4\u4e3aON\u5373\u662f\u5f00<\/p>\n<p>upload_tmp_dir<br \/>\nupload_tmp_dir\u7528\u6765\u8bf4\u660ePHP\u4e0a\u4f20\u7684\u6587\u4ef6\u653e\u7f6e\u7684\u4e34\u65f6\u76ee\u5f55\uff0c\u8981\u60f3\u4e0a\u4f20\u6587\u4ef6\uff0c\u5f97\u4fdd\u8bc1\u670d\u52a1\u5668\u6ca1\u6709\u5173\u95ed\u4e34\u65f6\u6587\u4ef6\u548c\u6709\u5bf9\u6587\u4ef6\u5939\u7684\u5199\u6743\u9650\uff0c\u5982\u679c\u672a\u6307\u5b9a\u5219PHP\u4f7f\u7528\u7cfb\u7edf\u9ed8\u8ba4\u503c<\/p>\n<p>upload_max_filesize<br \/>\n\u5141\u8bb8\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u7684\u6700\u5927\u503c\uff0c\u9ed8\u8ba4\u4e3a2M<\/p>\n<p>post_max_size<br \/>\n\u63a7\u5236\u5728\u91c7\u7528POST\u65b9\u6cd5\u8fdb\u884c\u4e00\u6b21\u8868\u5355\u63d0\u4ea4\u4e2dPHP\u6240\u80fd\u591f\u63a5\u6536\u7684\u6700\u5927\u6570\u636e\u91cf\u3002\u5982\u679c\u5e0c\u671b\u4f7f\u7528PHP\u6587\u4ef6\u4e0a\u4f20\u529f\u80fd\uff0c\u5219\u9700\u8981\u5c06\u6b64\u503c\u6539\u4e3a\u6bd4upload_max_filesize\u8981\u5927<\/p>\n<p>max_input_time<br \/>\n\u4ee5\u79d2\u4e3a\u5355\u4f4d\u5bf9\u901a\u8fc7POST\u3001GET\u4ee5\u53caPUT\u65b9\u5f0f\u63a5\u6536\u6570\u636e\u65f6\u95f4\u8fdb\u884c\u9650\u5236\u3002\u5982\u679c\u5e94\u7528\u7a0b\u5e8f\u6240\u8fd0\u884c\u73af\u5883\u5904\u5728\u4f4e\u901f\u94fe\u8def\u4e0a\uff0c\u5219\u9700\u8981\u589e\u52a0\u6b64\u503c\u4ee5\u9002\u5e94\u63a5\u6536\u6570\u636e\u6240\u9700\u7684\u66f4\u591a\u65f6\u95f4<\/p>\n<p>www.87717.com<br \/>\nmemory_limit<br \/>\n\u4e3a\u4e86\u907f\u514d\u6b63\u5728\u8fd0\u884c\u7684\u811a\u672c\u5927\u91cf\u4f7f\u7528\u7cfb\u7edf\u53ef\u7528\u5185\u5b58\uff0cPHP\u5141\u8bb8\u5b9a\u4e49\u5185\u5b58\u4f7f\u7528\u9650\u989d\u3002\u901a\u8fc7memory_limit\u53d8\u91cf\u6765\u6307\u5b9a\u5355\u4e2a\u811a\u672c\u7a0b\u5e8f\u53ef\u4ee5\u4f7f\u7528\u7684\u6700\u5927\u5185\u5b58\u5bb9\u91cf\u53d8\u91cfmemory_limit\u7684\u503c\u5e94\u5f53\u9002\u5f53\u5927\u4e8epost_max_size\u7684\u503c<\/p>\n<p>max_execution_time<br \/>\nmax_execution_time\u8bbe\u7f6e\u4e86\u5728\u5f3a\u5236\u7ec8\u6b62\u811a\u672c\u524dPHP\u7b49\u5f85\u811a\u672c\u6267\u884c\u5b8c\u6bd5\u7684\u65f6\u95f4\uff0c\u6b64\u65f6\u95f4\u4ee5\u79d2\u8ba1\u7b97\u3002\u5f53\u811a\u672c\u8fdb\u5165\u4e86\u4e00\u4e2a\u65e0\u9650\u5faa\u73af\u72b6\u6001\u65f6\u6b64\u53d8\u91cf\u975e\u5e38\u6709\u7528\u3002\u7136\u800c\uff0c\u5f53\u5b58\u5728\u4e00\u4e2a\u9700\u8981\u5f88\u957f\u65f6\u95f4\u5b8c\u6210\u7684\u5408\u6cd5\u6d3b\u52a8\u65f6\uff08\u4f8b\u5982\u4e0a\u4f20\u5927\u578b\u6587\u4ef6\uff09\uff0c\u8fd9\u9879\u529f\u80fd\u4e5f\u4f1a\u5bfc\u81f4\u64cd\u4f5c\u5931\u8d25\u3002\u5728\u8fd9\u6837\u7684\u60c5\u51b5\u4e0b\u5fc5\u987b\u8003\u8651\u5c06\u6b64\u53d8\u91cf\u503c\u589e\u52a0\uff0c\u4ee5\u907f\u514dPHP\u5728\u811a\u672c\u6b63\u5728\u6267\u884c\u67d0\u4e9b\u91cd\u8981\u8fc7\u7a0b\u7684\u65f6\u5019\u5c06\u811a\u672c\u5173\u95ed<\/p>\n<p>\u5bf9\u4e8elinux\u4e3b\u673a\uff0c\u53ef\u80fd\u5728\/etc\/httpd\/conf.d\/access.conf\/\u4e0b\u9762\u91cc\u9762\u8fd8\u6709php.conf \u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u53ef\u80fd\u4f1a\u89e3\u51b3\u4e00\u4e9b\u7cfb\u7edf\u7684\u6587\u4ef6\u5927\u5c0f\u9650\u5236\u95ee\u9898<\/p>\n<p>PHP\u4e2d\u4e0a\u4f20\u5927\u4f53\u79ef\u6587\u4ef6\u65f6\u9700\u8981\u7684\u8bbe\u7f6e<\/p>\n<p>\u6253\u5f00php.ini\uff0c\u9996\u5148\u627e\u5230<br \/>\n;;;;;;;;;;;;;;;;<br \/>\n; File Uploads ;<br \/>\n;;;;;;;;;;;;;;;;<br \/>\n\u533a\u57df\uff0c\u6709\u5f71\u54cd\u6587\u4ef6\u4e0a\u4f20\u7684\u4ee5\u4e0b\u51e0\u4e2a\u53c2\u6570\uff1a<\/p>\n<p>file_uploads = on ;\u662f\u5426\u5141\u8bb8\u901a\u8fc7HTTP\u4e0a\u4f20\u6587\u4ef6\u7684\u5f00\u5173\u3002\u9ed8\u8ba4\u4e3aON\u5373\u662f\u5f00<br \/>\nupload_tmp_dir ;\u6587\u4ef6\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\u4e0a\u5b58\u50a8\u4e34\u65f6\u6587\u4ef6\u7684\u5730\u65b9\uff0c\u5982\u679c\u6ca1\u6307\u5b9a\u5c31\u4f1a\u7528\u7cfb\u7edf\u9ed8\u8ba4\u7684\u4e34\u65f6\u6587\u4ef6\u5939<br \/>\nupload_max_filesize = 8m ;\u671b\u6587\u751f\u610f\uff0c\u5373\u5141\u8bb8\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u7684\u6700\u5927\u503c\u3002\u9ed8\u8ba4\u4e3a2M<\/p>\n<p>\u5728<br \/>\n;;;;;;;;;;;;;;;;;<br \/>\n; Data Handling ;<br \/>\n;;;;;;;;;;;;;;;;;<br \/>\n\u533a\u57df\uff0c\u8fd8\u6709\u4e00\u9879\uff1a<\/p>\n<p>post_max_size = 8m ;\u6307\u901a\u8fc7\u8868\u5355POST\u7ed9PHP\u7684\u6240\u80fd\u63a5\u6536\u7684\u6700\u5927\u503c\uff0c\u5305\u62ec\u8868\u5355\u91cc\u7684\u6240\u6709\u503c\u3002\u9ed8\u8ba4\u4e3a8M<\/p>\n<p>\u4e00\u822c\u5730\uff0c\u8bbe\u7f6e\u597d\u4e0a\u8ff0\u56db\u4e2a\u53c2\u6570\u540e\uff0c\u4e0a\u4f208M\u7684\u5927\u4f53\u79ef\u6587\u4ef6\uff0c\u53ea\u8bbe\u7f6e\u4e0a\u8ff0\u56db\u9879\u8fd8\u4e00\u5b9a\u80fd\u884c\u7684\u901a\u3002\u9664\u975e\u4f60\u7684\u7f51\u7edc\u771f\u6709100M\/S\u7684\u4e0a\u4f20\u9ad8\u901f\uff0c\u5426\u5219\u4f60\u8fd8\u5f97\u5173\u5fc3\u5173\u5fc3\u4e0b\u9762\u7684\u53c2\u6570\uff1a<\/p>\n<p>;;;;;;;;;;;;;;;;;;;<br \/>\n; Resource Limits ;<br \/>\n;;;;;;;;;;;;;;;;;;;<\/p>\n<p>max_execution_time = 600 ;\u6bcf\u4e2aPHP\u9875\u9762\u8fd0\u884c\u7684\u6700\u5927\u65f6\u95f4\u503c(\u79d2)\uff0c\u9ed8\u8ba430\u79d2<br \/>\nmax_input_time = 600 ;\u6bcf\u4e2aPHP\u9875\u9762\u63a5\u6536\u6570\u636e\u6240\u9700\u7684\u6700\u5927\u65f6\u95f4\uff0c\u9ed8\u8ba460\u79d2<br \/>\nmemory_limit = 8m ;\u6bcf\u4e2aPHP\u9875\u9762\u6240\u5403\u6389\u7684\u6700\u5927\u5185\u5b58\uff0c\u9ed8\u8ba48M<\/p>\n<p>\u628a\u4e0a\u8ff0\u53c2\u6570\u4fee\u6539\u540e\uff0c\u5728\u7f51\u7edc\u6240\u5141\u8bb8\u7684\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c\u5c31\u53ef\u4ee5\u4e0a\u4f20\u5927\u4f53\u79ef\u6587\u4ef6\u4e86\u3002<\/p>\n<p>\u7528php\u4e0a\u4f20\u6587\u4ef6\u4e3b\u8981\u662f\u7528$_FILES\u8fd9\u4e2a\u8d85\u5168\u5c40\u6570\u7ec4\uff0c\u5728\u8868\u5355form\u4e2d\u4e00\u5b9a\u8981\u52a0\u4e0a<\/p>\n<p>enctype=&#8221;multipart\/form-data&#8221;\u8fd9\u53e5\u8bdd\uff0c\u5426\u5219$_FILES\u662f\u5f97\u4e0d\u5230\u503c\u7684\u3002<br \/>\n$_FILES\u6570\u7ec4\u4fe1\u606f\u5982\u4e0b\uff1a<br \/>\n$_FILES[&#8216;upload_file&#8217;][&#8216;name&#8217;] \/\/\u5f97\u5230\u6587\u4ef6\u540d\u79f0<br \/>\n$_FILES[&#8216;upload_file&#8217;][&#8216;tmp_name&#8217;] \/\/\u5f97\u5230\u4e34\u65f6\u5b58\u50a8\u4f4d\u7f6e<br \/>\n$_FILES[&#8216;upload_file&#8217;][&#8216;size&#8217;] \/\/\u5f97\u5230\u6587\u4ef6\u5927\u5c0f<br \/>\n$_FILES[&#8216;upload_file&#8217;][&#8216;type&#8217;] \/\/\u5f97\u5230\u6587\u4ef6MIME\u7c7b\u578b<\/p>\n<p>\u4e0b\u9762\u662f\u5b9e\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;php\u4e0a\u4f20\u6587\u4ef6\u5b9e\u4f8b&lt;\/title&gt;&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;form enctype=&quot;multipart\/form-data&quot; action=&quot;&quot; method=&quot;post&quot;&gt;\r\n\u8bf7\u9009\u62e9\u6587\u4ef6\uff1a &lt;br&gt;\r\n&lt;input name=&quot;upload_file&quot; type=&quot;file&quot;&gt;&lt;br&gt;\r\n&lt;input type=&quot;submit&quot; value=&quot;\u63d0\u4ea4\u6587\u4ef6&quot;&gt;\r\n&lt;\/form&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n&lt;?\r\n$upload_file=$_FILES&#x5B;'upload_file']&#x5B;'tmp_name'];\r\n$upload_file_name=$_FILES&#x5B;'upload_file']&#x5B;'name'];\r\nif($upload_file){\r\n$file_size_max = 1000000;\/\/ 1M\u9650\u5236\u6587\u4ef6\u4e0a\u4f20\u6700\u5927\u5bb9\u91cf(bytes)\r\n$store_dir = &quot;E:\/&quot;;\/\/ \u4e0a\u4f20\u6587\u4ef6\u7684\u50a8\u5b58\u4f4d\u7f6e\r\n$accept_overwrite = 1;\/\/\u662f\u5426\u5141\u8bb8\u8986\u76d6\u76f8\u540c\u6587\u4ef6\r\n\/\/ \u68c0\u67e5\u6587\u4ef6\u5927\u5c0f\r\nif ($upload_file_size &gt; $file_size_max) {\r\n     echo &quot;\u5bf9\u4e0d\u8d77\uff0c\u4f60\u7684\u6587\u4ef6\u5bb9\u91cf\u5927\u4e8e\u89c4\u5b9a&quot;;\r\n     exit;\r\n}\r\n\/\/ \u68c0\u67e5\u8bfb\u5199\u6587\u4ef6\r\nif (file_exists($store_dir . $upload_file_name) &amp;&amp; !$accept_overwrite) {\r\n     Echo &quot;\u5b58\u5728\u76f8\u540c\u6587\u4ef6\u540d\u7684\u6587\u4ef6&quot;;\r\n     exit;\r\n}\r\n\/\/\u590d\u5236\u6587\u4ef6\u5230\u6307\u5b9a\u76ee\u5f55\r\nif (!move_uploaded_file($upload_file,$store_dir.$upload_file_name)) {\r\n     echo &quot;\u590d\u5236\u6587\u4ef6\u5931\u8d25&quot;;\r\n     exit;\r\n}\r\n}\r\nEcho &quot;&lt;p&gt;\u4f60\u4e0a\u4f20\u4e86\u6587\u4ef6:&quot;;\r\necho $_FILES&#x5B;'upload_file']&#x5B;'name'];\r\necho &quot;&lt;br&gt;&quot;;\r\n\/\/\u5ba2\u6237\u7aef\u673a\u5668\u6587\u4ef6\u7684\u539f\u540d\u79f0\u3002\r\nEcho &quot;\u6587\u4ef6\u7684 MIME \u7c7b\u578b\u4e3a:&quot;;\r\necho $_FILES&#x5B;'upload_file']&#x5B;'type'];\r\n\/\/\u6587\u4ef6\u7684 MIME \u7c7b\u578b\uff0c\u9700\u8981\u6d4f\u89c8\u5668\u63d0\u4f9b\u8be5\u4fe1\u606f\u7684\u652f\u6301\uff0c\u4f8b\u5982\u201cimage\/gif\u201d\u3002\r\necho &quot;&lt;br&gt;&quot;;\r\nEcho &quot;\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f:&quot;;\r\necho $_FILES&#x5B;'upload_file']&#x5B;'size'];\r\n\/\/\u5df2\u4e0a\u4f20\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u5355\u4f4d\u4e3a\u5b57\u8282\u3002\r\necho &quot;&lt;br&gt;&quot;;\r\nEcho &quot;\u6587\u4ef6\u4e0a\u4f20\u540e\u88ab\u4e34\u65f6\u50a8\u5b58\u4e3a:&quot;;\r\necho $_FILES&#x5B;'upload_file']&#x5B;'tmp_name'];\r\n\/\/\u6587\u4ef6\u88ab\u4e0a\u4f20\u540e\u5728\u670d\u52a1\u7aef\u50a8\u5b58\u7684\u4e34\u65f6\u6587\u4ef6\u540d\u3002\r\necho &quot;&lt;br&gt;&quot;;\r\n$Erroe=$_FILES&#x5B;'upload_file']&#x5B;'error'];\r\nswitch($Erroe){\r\n     case 0:\r\n       Echo &quot;\u4e0a\u4f20\u6210\u529f&quot;; break;\r\n     case 1:\r\n       Echo &quot;\u4e0a\u4f20\u7684\u6587\u4ef6\u8d85\u8fc7\u4e86 php.ini \u4e2d upload_max_filesize \u9009\u9879\u9650\u5236\u7684\u503c\r\n\r\n.&quot;; break;\r\n     case 2:\r\n       Echo &quot;\u4e0a\u4f20\u6587\u4ef6\u7684\u5927\u5c0f\u8d85\u8fc7\u4e86 HTML \u8868\u5355\u4e2d MAX_FILE_SIZE \u9009\u9879\u6307\u5b9a\u7684\u503c\r\n\r\n\u3002&quot;; break;\r\n     case 3:\r\n       Echo &quot;\u6587\u4ef6\u53ea\u6709\u90e8\u5206\u88ab\u4e0a\u4f20&quot;;break;\r\n     case 4:\r\n       Echo &quot;\u6ca1\u6709\u6587\u4ef6\u88ab\u4e0a\u4f20&quot;;break;\r\n}\r\n?&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1.\u4e0a\u4f20\u8868\u5355 upload.html \u7a0b\u5e8f\u4ee3\u7801 &lt;form enctype=&quot;multipar [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-243","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=243"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/243\/revisions"}],"predecessor-version":[{"id":5320,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/243\/revisions\/5320"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}