{"id":176,"date":"2013-03-07T19:56:52","date_gmt":"2013-03-07T11:56:52","guid":{"rendered":"http:\/\/fineyi.com\/?p=176"},"modified":"2013-03-07T19:56:52","modified_gmt":"2013-03-07T11:56:52","slug":"%e5%9c%a8thinkphp%e6%a1%86%e6%9e%b6%e4%b8%8b%e7%94%a8ajaxfileuploader%e6%8f%92%e4%bb%b6%e5%ae%9e%e7%8e%b0ajax%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0","status":"publish","type":"post","link":"http:\/\/www.fineyi.com\/?p=176","title":{"rendered":"\u5728ThinkPHP\u6846\u67b6\u4e0b\u7528AjaxFileUploader\u63d2\u4ef6\u5b9e\u73b0ajax\u6587\u4ef6\u4e0a\u4f20"},"content":{"rendered":"<p>\t\t\t\t<strong>\u5728ThinkPHP\u6846\u67b6\u4e0b\u7528AjaxFileUploader\u63d2\u4ef6\u5b9e\u73b0ajax\u6587\u4ef6\u4e0a\u4f20\uff0c\u652f\u6301\u591a\u79cd\u6587\u4ef6\u683c\u5f0f\uff0c\u9875\u9762\u65e0\u5237\u65b0\u4e0a\u4f20\u3002<\/strong><\/p>\n<p><strong>\u5728Lib\/Action\/\u76ee\u5f55\u4e0b\u521b\u5efaupAction.class.php\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre><!--?php\nclass upAction extends BaseAction{\n\npublic function index(){\n\t$this--->display();\n}\n\n\/*\n*@\u6587\u4ef6\u4e0a\u4f20\n*@author\tFineYi\n*@date\t\t2013-01-23\n*\/\npublic function upLoadFile(){\n\t$error = \"\";\n\t$msg = \"\";\n\t$fileElementName = 'fileToUpload';\n\tif(!empty($_FILES[$fileElementName]['error'])){\n\t\tswitch($_FILES[$fileElementName]['error']){\n\t\t\tcase '1':\n\t\t\t\t$error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';\n\t\t\t\tbreak;\n\t\t\tcase '2':\n\t\t\t\t$error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';\n\t\t\t\tbreak;\n\t\t\tcase '3':\n\t\t\t\t$error = 'The uploaded file was only partially uploaded';\n\t\t\t\tbreak;\n\t\t\tcase '4':\n\t\t\t\t$error = 'No file was uploaded.';\n\t\t\t\tbreak;\n\n\t\t\tcase '6':\n\t\t\t\t$error = 'Missing a temporary folder';\n\t\t\t\tbreak;\n\t\t\tcase '7':\n\t\t\t\t$error = 'Failed to write file to disk';\n\t\t\t\tbreak;\n\t\t\tcase '8':\n\t\t\t\t$error = 'File upload stopped by extension';\n\t\t\t\tbreak;\n\t\t\tcase '999':\n\t\t\tdefault:\n\t\t\t\t$error = 'No error code avaiable';\n\t\t}\n\t}elseif(empty($_FILES['fileToUpload']['tmp_name']) || $_FILES['fileToUpload']['tmp_name'] == 'none'){\n\t\t$error = 'No file was uploaded..';\n\t}else{\n\t\t\t$re = $this-&gt;up();\n\t\t\tif(!$re){\n\t\t\t\t$error = 'Up file fail';\n\t\t\t}\n\t\t\t$msg = $re['savename'];\t\/\/\u6587\u4ef6\u540d\n\t\t\t$path = '\/upload\/bizcoop\/'.$msg;\t\/\/\u6587\u4ef6\u8def\u5f84\n\t\t\t$size = $re['size'];\t\/\/\u6587\u4ef6\u5927\u5c0f\n\t}\t\t\n\techo json_encode(array('error'=&gt;$error,'msg'=&gt;$msg,'path'=&gt;$path,'size'=&gt;$size));exit;\n}\n\nprivate function up(){ \n\timport('@.Org.UploadFile');\/\/\u5c06\u4e0a\u4f20\u7c7bUploadFile.class.php\u62f7\u5230Lib\/Org\u6587\u4ef6\u5939\u4e0b\n\t$upload=new UploadFile();\n\n\t$upload-&gt;maxSize='-1';\/\/\u9ed8\u8ba4\u4e3a-1\uff0c\u4e0d\u9650\u5236\u4e0a\u4f20\u5927\u5c0f\n\t$upload-&gt;savePath= ICTSPACE_DIST_ROOT_PATH.'\/www\/upload\/bizcoop\/';\/\/\u4fdd\u5b58\u8def\u5f84\n\t$upload-&gt;saveRule=uniqid;\/\/\u4e0a\u4f20\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u4fdd\u5b58\u89c4\u5219\n\t$upload-&gt;uploadReplace=true;\/\/\u5982\u679c\u5b58\u5728\u540c\u540d\u6587\u4ef6\u662f\u5426\u8fdb\u884c\u8986\u76d6\n\t$upload-&gt;allowExts=array('jpg','jpeg','png','gif');\/\/\u51c6\u8bb8\u4e0a\u4f20\u7684\u6587\u4ef6\u7c7b\u578b\n\tif($upload-&gt;upload()){\n\t\t$info=$upload-&gt;getUploadFileInfo();\n\t\treturn $info[0];\n\t}else{\n\t\treturn false;\n\t\texit;\n\t} \n}\n\n}\n?&gt;<\/pre>\n<p><strong>\u5728\/Tpl\/default\/Up\/\u76ee\u5f55\u4e0b\u521b\u5efaindex.tpl\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/strong><\/p>\n<pre class=\"lang:default decode:true\">&lt;div id=\"content\"&gt;\n&lt;h1&gt;Ajax File Upload Demo&lt;\/h1&gt;\n&lt;img id=\"loading\" style=\"display: none;\" alt=\"\" src=\"__APP____PUBLIC__\/style\/img\/loading.gif\" \/&gt;\n\n&lt;form action=\"\" enctype=\"multipart\/form-data\" method=\"POST\" name=\"form\"&gt;\n&lt;table class=\"tableForm\" cellspacing=\"0\" cellpadding=\"0\"&gt;\n&lt;thead&gt;\n&lt;tr&gt;\n&lt;th&gt;&lt;\/th&gt;\n&lt;\/tr&gt;\n&lt;\/thead&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td&gt;&lt;input class=\"input\" id=\"fileToUpload\" type=\"file\" name=\"fileToUpload\" size=\"45\" \/&gt;&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr&gt;\n&lt;td&gt;&lt;button class=\"button\" id=\"buttonUpload\" onclick=\"return ajaxFileUpload();\"&gt;Upload&lt;\/button&gt;&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;\/tbody&gt;\n&lt;tbody&gt;\n&lt;tr&gt;\n&lt;td&gt;&lt;span&gt;\u5df2\u4e0a\u4f20\u7684\u9644\u4ef6:&lt;\/span&gt;&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;\/tbody&gt;\n&lt;tfoot&gt;&lt;\/tfoot&gt;\n&lt;\/table&gt;\n&lt;\/form&gt;&lt;\/div&gt;<\/pre>\n<p><strong>\u5728\/Lib\/Org\/\u76ee\u5f55\u4e0b\u653e\u5165ThinkPHP\u6587\u4ef6\u4e0a\u4f20\u7c7b\uff1a<\/strong><br \/>\n<strong>\u4e0b\u8f7dThinkPHP\u6269\u5c55\u5305<\/strong> <a title=\"thinkphp\u6269\u5c55\u5305\u4e0b\u8f7d\" href=\"http:\/\/www.thinkphp.cn\/download\/253.html\">\u4e0b\u8f7d<\/a><br \/>\n<strong>\u89e3\u538b\u7f29\u00a0 \u7c7b\u6587\u4ef6\u8def\u5f84<\/strong>\u00a0 \/Extend\/Library\/ORG\/Net\/UploadFile.class.php<\/p>\n<p><strong>\u4e0a\u4f20\u4e2dloading\u6587\u4ef6\uff1a<\/strong><a href=\"http:\/\/fineyi.com\/wp-content\/uploads\/2013\/03\/loading.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-181\" alt=\"loading\" src=\"http:\/\/fineyi.com\/wp-content\/uploads\/2013\/03\/loading.gif\" width=\"32\" height=\"32\" \/><\/a><\/p>\n<p><strong>demo\u4e0a\u4f20\u6548\u679c\uff1a<\/strong><br \/>\n<a href=\"http:\/\/fineyi.com\/wp-content\/uploads\/2013\/03\/0307201135.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-182\" alt=\"0307201135\" src=\"http:\/\/fineyi.com\/wp-content\/uploads\/2013\/03\/0307201135.jpg\" width=\"416\" height=\"181\" srcset=\"http:\/\/www.fineyi.com\/wp-content\/uploads\/2013\/03\/0307201135.jpg 416w, http:\/\/www.fineyi.com\/wp-content\/uploads\/2013\/03\/0307201135-300x131.jpg 300w\" sizes=\"auto, (max-width: 416px) 100vw, 416px\" \/><\/a><br \/>\n<strong>Jquery Ajax File Uploader\u63d2\u4ef6\u4e0b\u8f7d\u5730\u5740 <\/strong><a title=\"Jquery Ajax File Uploader\" href=\"http:\/\/www.phpletter.com\/download_project_version.php?version_id=34\" target=\"_blank\" rel=\"noopener\">\u4e0b\u8f7d<\/a>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728ThinkPHP\u6846\u67b6\u4e0b\u7528AjaxFileUploader\u63d2\u4ef6\u5b9e\u73b0ajax\u6587\u4ef6\u4e0a &hellip; <a href=\"http:\/\/www.fineyi.com\/?p=176\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a> <a href=\"http:\/\/www.fineyi.com\/?p=176\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"footnotes":""},"categories":[4,8],"tags":[12,38,46,72],"class_list":["post-176","post","type-post","status-publish","format-standard","hentry","category-js","category-php","tag-ajax","tag-php","tag-thinkphp","tag-72"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.fineyi.com\/index.php?rest_route=\/wp\/v2\/posts\/176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.fineyi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.fineyi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.fineyi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.fineyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=176"}],"version-history":[{"count":0,"href":"http:\/\/www.fineyi.com\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.fineyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fineyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fineyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}