{"id":49326,"date":"2024-12-02T10:07:34","date_gmt":"2024-12-02T02:07:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49326\/"},"modified":"2024-12-02T10:07:34","modified_gmt":"2024-12-02T02:07:34","slug":"%e5%a6%82%e4%bd%95%e7%94%a8php%e6%ad%a3%e7%a1%ae%e5%9c%b0%e5%b0%86%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%e7%a7%bb%e5%8a%a8%e5%88%b0%e6%8c%87%e5%ae%9a%e4%bd%8d%e7%bd%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49326\/","title":{"rendered":"\u5982\u4f55\u7528PHP\u6b63\u786e\u5730\u5c06\u4e0a\u4f20\u6587\u4ef6\u79fb\u52a8\u5230\u6307\u5b9a\u4f4d\u7f6e\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u7528PHP\u6b63\u786e\u5730\u5c06\u4e0a\u4f20\u6587\u4ef6\u79fb\u52a8\u5230\u6307\u5b9a\u4f4d\u7f6e\uff1f<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u7528PHP\u6b63\u786e\u5730\u5c06\u4e0a\u4f20\u6587\u4ef6\u79fb\u52a8\u5230\u6307\u5b9a\u4f4d\u7f6e\uff1f\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241129\/173286507767496c35a4417.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u7528PHP\u6b63\u786e\u5730\u5c06\u4e0a\u4f20\u6587\u4ef6\u79fb\u52a8\u5230\u6307\u5b9a\u4f4d\u7f6e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7528PHP\u6b63\u786e\u5730\u5c06\u4e0a\u4f20\u6587\u4ef6\u79fb\u52a8\u5230\u6307\u5b9a\u4f4d\u7f6e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06\u8f93\u5165\u6587\u4ef6\u4e0a\u4f20\u5230\u4e0d\u540c\u7684\u4f4d\u7f6e<\/strong><\/p>\n<p>\u5982\u4f55\u5c06\u9009\u5b9a\u7684\u6587\u4ef6\u4ece input \u6587\u4ef6\u57df\u4f20\u8f93\u5230\u53e6\u4e00\u4e2a\u4f4d\u7f6e\uff1f<\/p>\n<p><strong>\u95ee\u9898\u5206\u6790<\/strong><\/p>\n<p>\u5982\u95ee\u9898\u6240\u8ff0\uff0c\u4f7f\u7528 input \u5143\u7d20\u4e0a\u4f20\u6587\u4ef6\u5e76\u5c06\u5176\u8def\u5f84\u5b58\u50a8\u5728 repath \u53d8\u91cf\u4e2d\u3002\u7136\u540e\uff0c\u4f7f\u7528 ajax \u5c06\u8def\u5f84\u4f20\u9012\u5230 php \u811a\u672c\uff0c\u5e76\u5728 php \u811a\u672c\u4e2d\u5c1d\u8bd5\u4f7f\u7528 rename \u51fd\u6570\u5c06\u6587\u4ef6\u79fb\u52a8\u5230\u65b0\u8def\u5f84\u3002\u4f46\u662f\uff0c\u6b64\u65b9\u6cd5\u4e0d\u8d77\u4f5c\u7528\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u6b63\u786e\u7684\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528 html form \u5143\u7d20\u548c multipart\/form-data \u7f16\u7801\u7c7b\u578b\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>&lt;form action='xx.php' method='post' enctype='multipart\/form-data'&gt;\n  &lt;input type='file' name='pic' accept='image\/*' id='file'\/&gt;\n  &lt;input type='submit' name='btn'\/&gt;\n&lt;\/form&gt;<\/pre>\n<p>\u5728 php \u811a\u672c\u4e2d\uff0c\u4f7f\u7528 $_files \u6570\u7ec4\u63a5\u6536\u6587\u4ef6\u4fe1\u606f\uff1a<\/p>\n<pre>$temporary_path = $_FILES['pic']['tmp_name'];\n$new_path = '.\/1.jpg';\nif (move_uploaded_file($temporary_path, $new_path)) {\n  \/\/ \u79fb\u52a8\u6210\u529f\n} else {\n  \/\/ \u79fb\u52a8\u5931\u8d25\n}<\/pre>\n<p>move_uploaded_file \u51fd\u6570\u5c06\u6587\u4ef6\u4ece\u4e34\u65f6\u4f4d\u7f6e\u79fb\u52a8\u5230\u6307\u5b9a\u7684\u8def\u5f84\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u7528PHP\u6b63\u786e\u5730\u5c06\u4e0a\u4f20\u6587\u4ef6\u79fb\u52a8\u5230\u6307\u5b9a\u4f4d\u7f6e\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u7528PHP\u6b63\u786e\u5730\u5c06\u4e0a\u4f20\u6587\u4ef6\u79fb\u52a8\u5230\u6307\u5b9a\u4f4d\u7f6e\uff1f \u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0\u300a\u5982\u4f55\u7528PHP\u6b63\u786e\u5730\u5c06\u4e0a\u4f20\u6587\u4ef6\u79fb\u52a8\u5230\u6307\u5b9a\u4f4d\u7f6e\uff1f\u300b\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01 \u5982\u4f55\u5c06\u8f93\u5165\u6587\u4ef6\u4e0a\u4f20\u5230\u4e0d\u540c\u7684\u4f4d\u7f6e \u5982\u4f55\u5c06\u9009\u5b9a\u7684\u6587\u4ef6\u4ece input \u6587\u4ef6\u57df\u4f20\u8f93\u5230\u53e6\u4e00\u4e2a\u4f4d\u7f6e\uff1f \u95ee\u9898\u5206\u6790 \u5982\u95ee\u9898\u6240\u8ff0\uff0c\u4f7f\u7528 input \u5143\u7d20\u4e0a\u4f20\u6587\u4ef6\u5e76\u5c06\u5176\u8def\u5f84\u5b58\u50a8\u5728 repath \u53d8\u91cf\u4e2d\u3002\u7136\u540e\uff0c\u4f7f\u7528 ajax \u5c06\u8def\u5f84\u4f20\u9012\u5230 php \u811a\u672c\uff0c\u5e76\u5728 php \u811a\u672c\u4e2d\u5c1d\u8bd5\u4f7f\u7528 rename \u51fd\u6570\u5c06\u6587\u4ef6\u79fb\u52a8\u5230\u65b0\u8def\u5f84\u3002\u4f46\u662f\uff0c\u6b64\u65b9\u6cd5\u4e0d\u8d77\u4f5c\u7528\u3002 \u89e3\u51b3\u65b9\u6848 \u6b63\u786e\u7684\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528 html form \u5143\u7d20\u548c multipart\/form-data \u7f16\u7801\u7c7b\u578b\uff0c\u5982\u4e0b\u6240\u793a\uff1a &lt;form action=&#8217;xx.php&#8217; method=&#8217;post&#8217; enctype=&#8217;multipart\/form-data&#8217;&gt; &lt;input type=&#8217;file&#8217; name=&#8217;pic&#8217; accept=&#8217;image\/*&#8217; id=&#8217;file&#8217;\/&gt; &lt;input type=&#8217;submit&#8217; name=&#8217;btn&#8217;\/&gt; &lt;\/form&gt; \u5728 php \u811a\u672c\u4e2d\uff0c\u4f7f\u7528 $_files \u6570\u7ec4\u63a5\u6536\u6587\u4ef6\u4fe1\u606f\uff1a $temporary_path = $_FILES[&#8216;pic&#8217;][&#8216;tmp_name&#8217;]; $new_path = &#8216;.\/1.jpg&#8217;; if (move_uploaded_file($temporary_path, $new_path)) { [&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-49326","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49326","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=49326"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49326\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}