{"id":58,"date":"2023-06-05T13:29:32","date_gmt":"2023-06-05T05:29:32","guid":{"rendered":"http:\/\/pro369.com\/php\/?p=58"},"modified":"2019-04-22T06:48:00","modified_gmt":"2019-04-22T06:48:00","slug":"%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8php%e4%b8%8a%e5%82%b3%e6%96%87%e4%bb%b6%e7%9a%84%e6%96%b9%e6%b3%95%ef%bc%88php%e7%a8%8b%e5%bc%8f%e8%a8%ad%e8%a8%88%e5%95%8f%e9%a1%8c%e8%88%87%e7%ad%94%e8%a6%86%efb","status":"publish","type":"post","link":"https:\/\/por.tw\/php\/%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8php%e4%b8%8a%e5%82%b3%e6%96%87%e4%bb%b6%e7%9a%84%e6%96%b9%e6%b3%95%ef%bc%88php%e7%a8%8b%e5%bc%8f%e8%a8%ad%e8%a8%88%e5%95%8f%e9%a1%8c%e8%88%87%e7%ad%94%e8%a6%86%efb\/","title":{"rendered":"\u5982\u4f55\u5229\u7528PHP\u4e0a\u50b3\u6587\u4ef6\u7684\u65b9\u6cd5\uff08PHP\u7a0b\u5f0f\u8a2d\u8a08\u554f\u984c\u8207\u7b54\u8986\uff09"},"content":{"rendered":"<p><font size=\"3\" color=\"#008000\"><strong>PHP\u7a0b\u5f0f\u8a2d\u8a08\u554f\u984c\u8aee\u8a62\uff1a<br \/> \u6211\u60f3\u5229\u7528PHP\u4e0a\u50b3\u6587\u4ef6\uff0c\u5176\u65b9\u6cd5\u70ba\u4f55\uff1f<\/strong><\/font><br \/> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/> <font color=\"#ff0000\"><strong>PHP\u7a0b\u5f0f\u8a2d\u8a08\u554f\u984c\u56de\u8986\uff1a<br \/> <font color=\"#800080\">\u60a8\u8981\u5229\u7528PHP\u4e0a\u50b3\u6587\u4ef6\uff0c\u53ef\u4ee5\u53c3\u8003\u4ee5\u4e0b\u7684\u7bc4\u4f8b\uff1a<\/font><\/strong><\/font><br \/> &lt;html&gt;&lt;head&gt;<br \/> &lt;title&gt;\u4e0a\u8f09\u6587\u4ef6\u8868\u55ae&lt;\/title&gt;&lt;\/head&gt;<br \/> &lt;body&gt;<br \/> &lt;form enctype=&quot;multipart\/form-data&quot; action=&quot;&quot; method=&quot;post&quot;&gt;<br \/> \u8acb\u9078\u64c7\u6a94\uff1a &lt;br&gt;<br \/> &lt;input name=&quot;upload_file&quot; type=&quot;file&quot;&gt;&lt;br&gt;<br \/> &lt;input type=&quot;submit&quot; value=&quot;\u4e0a\u50b3\u6587\u4ef6&quot;&gt;<br \/> &lt;\/form&gt;<br \/> &lt;\/body&gt;<br \/> &lt;\/html&gt;<\/p>\n<p> &lt;?<br \/> $upload_file=$_FILES[&#39;upload_file&#39;][&#39;tmp_name&#39;];<br \/> $upload_file_name=$_FILES[&#39;upload_file&#39;][&#39;name&#39;];<\/p>\n<p> if($upload_file){<br \/> $file_size_max = 1000*1000;\/\/ 1M\u9650\u5236\u6a94\u4e0a\u50b3\u6700\u5927\u5bb9\u91cf(bytes)<br \/> $store_dir = &quot;d:\/&quot;;\/\/ \u4e0a\u50b3\u6a94\u7684\u5132\u5b58\u4f4d\u7f6e<br \/> $accept_overwrite = 1;\/\/\u662f\u5426\u5141\u8a31\u8986\u84cb\u76f8\u540c\u6a94<br \/> \/\/ \u6aa2\u67e5\u6a94\u5927\u5c0f<br \/> if ($upload_file_size &gt; $file_size_max) {<br \/> echo &quot;\u5c0d\u4e0d\u8d77\uff0c\u4f60\u7684\u6a94\u5bb9\u91cf\u5927\u65bc\u898f\u5b9a&quot;;<br \/> exit;<br \/> }<\/p>\n<p> \/\/ \u6aa2\u67e5\u8b80\u5beb\u6a94<br \/> if (file_exists($store_dir . $upload_file_name) &amp;&amp; !$accept_overwrite) {<br \/> Echo&nbsp;&nbsp; &quot;\u5b58\u5728\u76f8\u540c\u6a94\u6848\u540d\u7684\u6587\u4ef6&quot;;<br \/> exit;<br \/> }<\/p>\n<p> \/\/\u8907\u88fd\u6a94\u5230\u6307\u5b9a\u76ee\u9304<br \/> if (!move_uploaded_file($upload_file,$store_dir.$upload_file_name)) {<br \/> echo &quot;\u8907\u88fd\u6a94\u5931\u6557&quot;;<br \/> exit;<br \/> }<\/p>\n<p> }<\/p>\n<p> Echo&nbsp;&nbsp; &quot;&lt;p&gt;\u4f60\u4e0a\u50b3\u4e86\u6587\u4ef6:&quot;;<br \/> echo&nbsp; $_FILES[&#39;upload_file&#39;][&#39;name&#39;];<br \/> echo &quot;&lt;br&gt;&quot;;<br \/> \/\/\u7528\u6236\u7aef\u6a5f\u5668\u6587\u4ef6\u7684\u539f\u540d\u7a31\u3002<\/p>\n<p> Echo&nbsp;&nbsp; &quot;\u6587\u4ef6\u7684 MIME \u985e\u578b\u70ba:&quot;;<br \/> echo $_FILES[&#39;upload_file&#39;][&#39;type&#39;];<br \/> \/\/\u6a94\u7684 MIME \u985e\u578b\uff0c\u9700\u8981\u6d41\u89bd\u5668\u63d0\u4f9b\u8a72\u8cc7\u8a0a\u7684\u652f\u63f4\uff0c\u4f8b\u5982&ldquo;image\/gif&rdquo;\u3002<br \/> echo &quot;&lt;br&gt;&quot;;<\/p>\n<p> Echo&nbsp;&nbsp; &quot;\u4e0a\u50b3\u6587\u4ef6\u5927\u5c0f:&quot;;<br \/> echo $_FILES[&#39;upload_file&#39;][&#39;size&#39;];<br \/> \/\/\u5df2\u4e0a\u50b3\u6a94\u7684\u5927\u5c0f\uff0c\u55ae\u4f4d\u70ba\u4f4d\u5143\u7d44\u3002<br \/> echo &quot;&lt;br&gt;&quot;;<\/p>\n<p> Echo&nbsp;&nbsp; &quot;\u6a94\u4e0a\u50b3\u5f8c\u88ab\u81e8\u6642\u5132\u5b58\u70ba:&quot;;<br \/> echo $_FILES[&#39;upload_file&#39;][&#39;tmp_name&#39;];<br \/> \/\/\u6a94\u88ab\u4e0a\u50b3\u5f8c\u5728\u670d\u52d9\u7aef\u5132\u5b58\u7684\u66ab\u5b58\u6a94\u6848\u540d\u3002<br \/> echo &quot;&lt;br&gt;&quot;;<\/p>\n<p> $Erroe=$_FILES[&#39;upload_file&#39;][&#39;error&#39;];<br \/> switch($Erroe){<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 0:<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Echo&nbsp;&nbsp; &quot;\u4e0a\u50b3\u6210\u529f&quot;; break;<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 1:<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Echo&nbsp;&nbsp; &quot;\u4e0a\u50b3\u7684\u6587\u4ef6\u8d85\u904e\u4e86 php.ini \u4e2d upload_max_filesize \u9078\u9805\u9650\u5236\u7684\u503c.&quot;; break;<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 2:<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Echo&nbsp;&nbsp; &quot;\u4e0a\u50b3\u6a94\u7684\u5927\u5c0f\u8d85\u904e\u4e86 HTML \u8868\u55ae\u4e2d MAX_FILE_SIZE \u9078\u9805\u6307\u5b9a\u7684\u503c\u3002&quot;;&nbsp;&nbsp;&nbsp; break;<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 3:<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Echo&nbsp;&nbsp; &quot;\u6a94\u53ea\u6709\u90e8\u5206\u88ab\u4e0a\u50b3&quot;;break;<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 4:<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Echo&nbsp;&nbsp; &quot;\u6c92\u6709\u6a94\u88ab\u4e0a\u50b3&quot;;break;<br \/> }<br \/> ?&gt;<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u7a0b\u5f0f\u8a2d\u8a08\u554f\u984c\u8aee\u8a62\uff1a \u6211\u60f3\u5229\u7528PHP\u4e0a\u50b3\u6587\u4ef6\uff0c\u5176\u65b9\u6cd5\u70ba\u4f55\uff1f &#8212;&#8212;&#8212;&#038;# [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":391,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[22],"class_list":["post-58","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts\/58"}],"collection":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/comments?post=58"}],"version-history":[{"count":0,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/media\/391"}],"wp:attachment":[{"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/por.tw\/php\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}