{"id":49062,"date":"2024-12-02T12:34:33","date_gmt":"2024-12-02T04:34:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49062\/"},"modified":"2024-12-02T12:34:33","modified_gmt":"2024-12-02T04:34:33","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-jquery-fileupload-%e9%80%9a%e8%bf%87-ajax-%e5%92%8c-php-%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49062\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 jQuery FileUpload \u901a\u8fc7 Ajax \u548c PHP \u4e0a\u4f20\u6587\u4ef6\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 jQuery FileUpload \u901a\u8fc7 Ajax \u548c PHP \u4e0a\u4f20\u6587\u4ef6\uff1f<\/h1>\n<p><span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 jQuery FileUpload \u901a\u8fc7 Ajax \u548c PHP \u4e0a\u4f20\u6587\u4ef6\uff1f\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241108\/1731048159672db2dfa7d1b.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 jQuery FileUpload \u901a\u8fc7 Ajax \u548c PHP \u4e0a\u4f20\u6587\u4ef6\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 jQuery FileUpload \u901a\u8fc7 Ajax \u548c PHP \u4e0a\u4f20\u6587\u4ef6\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 jquery fileupload \u4e2d\u7ed3\u5408 ajax \u548c php \u4e0a\u4f20\u6587\u4ef6<\/strong><\/p>\n<p>\u60f3\u8981\u901a\u8fc7 jquery fileupload \u501f\u52a9 ajax \u5f02\u6b65\u4e0a\u4f20\u6587\u4ef6\u5230 php \u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u793a\u4f8b\uff1a<\/p>\n<p><strong>html<\/strong><\/p>\n<pre>&lt;form id=\"upload-form\" action=\"upload.php\" method=\"post\" enctype=\"multipart\/form-data\"&gt;\n  &lt;input type=\"file\" name=\"file\" \/&gt;\n  &lt;input type=\"submit\" value=\"\u4e0a\u4f20\" \/&gt;\n&lt;\/form&gt;<\/pre>\n<p><strong>javascript<\/strong><\/p>\n<pre>\/\/ \u521d\u59cb\u5316 fileupload\n$('#upload-form').fileupload({\n  url: 'upload.php',\n  datatype: 'json',\n  done: function(e, data) {\n    \/\/ \u6587\u4ef6\u4e0a\u4f20\u6210\u529f\u540e\u5904\u7406\n    console.log(data.result);\n  },\n  fail: function(e, data) {\n    \/\/ \u6587\u4ef6\u4e0a\u4f20\u5931\u8d25\u540e\u5904\u7406\n    console.error(data.error);\n  }\n});<\/pre>\n<p><strong>php<\/strong><\/p>\n<pre>&lt;?php\n\/\/ \u5904\u7406\u4e0a\u4f20\u6587\u4ef6\nif (isset($_FILES['file'])) {\n  \/\/ \u4fdd\u5b58\u6587\u4ef6\n  move_uploaded_file($_FILES['file']['tmp_name'], 'uploads\/' . $_FILES['file']['name']);\n\n  \/\/ \u8f93\u51fa\u7ed3\u679c\n  echo json_encode(['result' =&gt; '\u4e0a\u4f20\u6210\u529f']);\n} else {\n  echo json_encode(['error' =&gt; '\u4e0a\u4f20\u5931\u8d25']);\n}\n?&gt;<\/pre>\n<p><strong>\u53c2\u8003\u793a\u4f8b<\/strong><\/p>\n<p>\u8bf7\u53c2\u9605\u4ee5\u4e0b\u5b8c\u6574\u793a\u4f8b\uff1a<br \/>[jquery+ajax+php\u56fe\u7247\u4e0a\u4f20](http:\/\/www.cnblogs.com\/xumengxuan\/archive\/2013\/01\/10\/2855473.html)<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 jQuery FileUpload \u901a\u8fc7 Ajax \u548c PHP \u4e0a\u4f20\u6587\u4ef6\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 jQuery FileUpload \u901a\u8fc7 Ajax \u548c PHP \u4e0a\u4f20\u6587\u4ef6\uff1f \u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898\u662f\u300a\u5982\u4f55\u4f7f\u7528 jQuery FileUpload \u901a\u8fc7 Ajax \u548c PHP \u4e0a\u4f20\u6587\u4ef6\uff1f\u300b\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e\u6587\u7ae0\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01 \u5728 jquery fileupload \u4e2d\u7ed3\u5408 ajax \u548c php \u4e0a\u4f20\u6587\u4ef6 \u60f3\u8981\u901a\u8fc7 jquery fileupload \u501f\u52a9 ajax \u5f02\u6b65\u4e0a\u4f20\u6587\u4ef6\u5230 php \u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u793a\u4f8b\uff1a html &lt;form id=&#8221;upload-form&#8221; action=&#8221;upload.php&#8221; method=&#8221;post&#8221; enctype=&#8221;multipart\/form-data&#8221;&gt; &lt;input type=&#8221;file&#8221; name=&#8221;file&#8221; \/&gt; &lt;input type=&#8221;submit&#8221; value=&#8221;\u4e0a\u4f20&#8221; \/&gt; &lt;\/form&gt; javascript \/\/ \u521d\u59cb\u5316 fileupload $(&#8216;#upload-form&#8217;).fileupload({ url: &#8216;upload.php&#8217;, datatype: [&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-49062","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49062","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=49062"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49062\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}