{"id":48988,"date":"2024-12-02T10:07:43","date_gmt":"2024-12-02T02:07:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48988\/"},"modified":"2024-12-02T10:07:43","modified_gmt":"2024-12-02T02:07:43","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-jquery-fileupload%e3%80%81ajax-%e5%92%8c-php-%e5%ae%9e%e7%8e%b0%e5%a4%9a%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48988\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 jQuery Fileupload\u3001Ajax \u548c PHP \u5b9e\u73b0\u591a\u6587\u4ef6\u4e0a\u4f20\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 jQuery Fileupload\u3001Ajax \u548c PHP \u5b9e\u73b0\u591a\u6587\u4ef6\u4e0a\u4f20\uff1f<\/h1>\n<p><span style=\"font-size: 15px\">\u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 jQuery Fileupload\u3001Ajax \u548c PHP \u5b9e\u73b0\u591a\u6587\u4ef6\u4e0a\u4f20\uff1f\u300b<\/span>\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241105\/1730818304672a31007f7dc.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 jQuery Fileupload\u3001Ajax \u548c PHP \u5b9e\u73b0\u591a\u6587\u4ef6\u4e0a\u4f20\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 jQuery Fileupload\u3001Ajax \u548c PHP \u5b9e\u73b0\u591a\u6587\u4ef6\u4e0a\u4f20\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 jquery fileupload\u3001ajax \u548c php \u4e0a\u4f20\u6587\u4ef6<\/strong><\/p>\n<p>\u60f3\u8981\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 jquery fileupload\u3001ajax \u548c php \u4e0a\u4f20\u6587\u4ef6\uff1f\u8bf7\u770b\u4ee5\u4e0b\u793a\u4f8b\uff1a<\/p>\n<pre>&lt;html&gt;\n&lt;head&gt;\n    &lt;script src=\"jquery-1.11.3.min.js\"&gt;&lt;\/script&gt;\n    &lt;script src=\"jquery.fileupload.js\"&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;form id=\"fileupload\"&gt;\n        &lt;input type=\"file\" name=\"files[]\" multiple=\"multiple\"&gt;\n    &lt;\/form&gt;\n\n    &lt;script&gt;\n        $('#fileupload').fileupload({\n            url: 'upload.php',\n            datatype: 'json',\n            done: function (e, data) {\n                $.each(data.result.files, function (index, file) {\n                    $('&lt;p\/&gt;').text(file.name).appendto('#files');\n                });\n            }\n        });\n    &lt;\/script&gt;\n\n    &lt;div id=\"files\"&gt;&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>upload.php \u6587\u4ef6\uff1a<\/p>\n<pre>&lt;?php\nif (isset($_FILES['files'])) {\n    foreach ($_FILES['files']['error'] as $key =&gt; $error) {\n        if ($error == UPLOAD_ERR_OK) {\n            move_uploaded_file(\n                $_FILES['files']['tmp_name'][$key],\n                'uploads\/' . $_FILES['files']['name'][$key]\n            );\n        }\n    }\n\n    echo json_encode([\n        'files' =&gt; $_FILES['files']\n    ]);\n}<\/pre>\n<p>\u8be5\u4ee3\u7801\u5c55\u793a\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u591a\u6587\u4ef6\u4e0a\u4f20\u8868\u5355\uff0c\u4f7f\u7528 jquery fileupload \u63d2\u4ef6\u5904\u7406\u6587\u4ef6\u4e0a\u4f20\uff0c\u5e76\u901a\u8fc7 ajax \u5c06\u6587\u4ef6\u53d1\u9001\u5230 php \u811a\u672c\u4ee5\u4fdd\u5b58\u5b83\u4eec\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u4f7f\u7528 jQuery Fileupload\u3001Ajax \u548c PHP \u5b9e\u73b0\u591a\u6587\u4ef6\u4e0a\u4f20\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 jQuery Fileupload\u3001Ajax \u548c PHP \u5b9e\u73b0\u591a\u6587\u4ef6\u4e0a\u4f20\uff1f \u6709\u5fd7\u8005\uff0c\u4e8b\u7adf\u6210\uff01\u5982\u679c\u4f60\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u90a3\u4e48\u672c\u6587\u300a\u5982\u4f55\u4f7f\u7528 jQuery Fileupload\u3001Ajax \u548c PHP \u5b9e\u73b0\u591a\u6587\u4ef6\u4e0a\u4f20\uff1f\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff01\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~ \u5982\u4f55\u4f7f\u7528 jquery fileupload\u3001ajax \u548c php \u4e0a\u4f20\u6587\u4ef6 \u60f3\u8981\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 jquery fileupload\u3001ajax \u548c php \u4e0a\u4f20\u6587\u4ef6\uff1f\u8bf7\u770b\u4ee5\u4e0b\u793a\u4f8b\uff1a &lt;html&gt; &lt;head&gt; &lt;script src=&#8221;jquery-1.11.3.min.js&#8221;&gt;&lt;\/script&gt; &lt;script src=&#8221;jquery.fileupload.js&#8221;&gt;&lt;\/script&gt; &lt;\/head&gt; &lt;body&gt; &lt;form id=&#8221;fileupload&#8221;&gt; &lt;input type=&#8221;file&#8221; name=&#8221;files[]&#8221; multiple=&#8221;multiple&#8221;&gt; &lt;\/form&gt; &lt;script&gt; $(&#8216;#fileupload&#8217;).fileupload({ url: &#8216;upload.php&#8217;, datatype: &#8216;json&#8217;, done: function (e, data) { $.each(data.result.files, function (index, file) { [&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-48988","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48988","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=48988"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48988\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}