{"rsdb":{"rid":"242900","subhead":"","postdate":"0","aid":"167231","fid":"78","uid":"1","topic":"1","content":"
\n

\u6587\u4ef6\u7684\u4e0a\u4f20\u548c\u4e0b\u8f7d<\/p> \n

1->\u6587\u4ef6\u7684\u4e0a\u4f20<\/p> \n

\u6587\u4ef6\u7684\u4e0a\u4f20\uff0c\u91c7\u7528\u7684\u662fuploadify.js\u8fd9\u4e2a\u63d2\u4ef6.<\/p> \n

\u672c\u4e8b\u4f8b\u5b9e\u73b0\u7684\u662f\u4e0a\u4f20\u56fe\u7247\u6587\u4ef6\uff0c\u5176\u4ed6\u7684\u6587\u4ef6\u4e0a\u4f20\u4e5f\u4e00\u6837\u3002<\/p> \n

2->\u6587\u4ef6\u7684\u4e0b\u8f7d<\/p> \n

\u6587\u4ef6\u7684\u4e0b\u8f7d\u6709\u4e24\u4e2a\u5b9e\u73b0\u7684\u65b9\u5f0f\uff1a<\/p> \n

1->url\u8def\u5f84\u6307\u5411\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u6d4f\u89c8\u5668\u81ea\u884c\u4e0b\u8f7d\u3002\u4f46\u6b64\u65b9\u6cd5\u5b58\u5728\u7f3a\u9677\uff1a\u56fe\u7247\u6587\u4ef6\uff0ctext\uff0cpdf\u7b49\u6587\u4ef6\u4f1a\u5728\u6d4f\u89c8\u5668\u4e2d\u81ea\u52a8\u663e\u793a\uff0c\u4e0d\u4f1a\u6267\u884c\u4e0b\u8f7d\u529f\u80fd<\/p> \n

2->\u4f7f\u7528gin \u6682\u65f6\u6ca1\u5e26\u6709\u7684\u4e0b\u8f7d\u65b9\u6cd5<\/p> \n

3>\u65b0\u5efa\u4e00\u4e2afileopt.go\u63a7\u5236\u5668,\u5177\u4f53\u4ee3\u7801\u5982\u4e0b:<\/p> \n

  <\/p> \n

\n
package controllers\n\nimport (\n\t"io"\n\t"log"\n\t"os"\n\t"fmt"\n\t"github.com\/gin-gonic\/gin"\n\t"net\/http"\n)\n\/**\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u64cd\u4f5c\u9875\u9762**\/\nfunc Fileopthtml(c *gin.Context){\n\tc.HTML(http.StatusOK, "fileopt.html", gin.H{\n\t\t"title": "GIN: \u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u64cd\u4f5c\u5e03\u5c40\u9875\u9762",\n\t})\n}\n\n\/**\u4e0a\u4f20\u65b9\u6cd5**\/\nfunc Fileupload(c *gin.Context){\n\t\/\/\u5f97\u5230\u4e0a\u4f20\u7684\u6587\u4ef6\n\tfile, header, err := c.Request.FormFile("image") \/\/image\u8fd9\u4e2a\u662fuplaodify\u53c2\u6570\u5b9a\u4e49\u4e2d\u7684   'fileObjName':'image'\n\tif err != nil {\n\t\tc.String(http.StatusBadRequest, "Bad request")\n\t\treturn\n\t}\n\t\/\/\u6587\u4ef6\u7684\u540d\u79f0\n\tfilename := header.Filename\n\n\tfmt.Println(file, err, filename)\n    \/\/\u521b\u5efa\u6587\u4ef6 \n\tout, err := os.Create("static\/uploadfile\/"+filename)\n\t\/\/\u6ce8\u610f\u6b64\u5904\u7684 static\/uploadfile\/ \u4e0d\u662f\/static\/uploadfile\/\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer out.Close()\n\t_, err = io.Copy(out, file)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tc.String(http.StatusCreated, "upload successful")\n}\n\n\/**\u4e0b\u8f7d\u65b9\u6cd5**\/\nfunc Filedown(c *gin.Context){\n\t\/\/\u6682\u65f6\u6ca1\u6709\u63d0\u4f9b\u65b9\u6cd5\n}\n<\/pre> \n <\/div> \n 

\u3000\u3000<\/p> \n

4>\u65b0\u5efa\u4e00\u4e2ahtml\u9875\u9762,\u540d\u4e3afileopt.html,\u5176\u4ee3\u7801\u5982\u4e0b:<\/p> \n

 <\/p> \n

\n
<!DOCTYPE html>\n \n<html>\n      <head>\n        <title>\u9996\u9875 - \u7528\u6237\u5217\u8868\u9875\u9762<\/title>\n        <link rel="shortcut icon" href="\/static\/img\/favicon.png" \/> \n        <link rel="stylesheet" href="\/static\/uploadify\/uploadify.css" rel="stylesheet"\/>\n        <script type="text\/java<\/a> script" src="\/static\/js\/jquery-2.1.1.min.js"><\/script> \n        <script src="\/static\/uploadify\/jquery.uploadify.min.js"><\/script>\n      <\/head>       \n    <body>\n        <!--\u4e0a\u4f20\u90e8\u5206-->\n        <form method="POST" action="\/Home\/UploadFile" enctype="multipart\/form-data">   \n            <input type="file" name="image" id="file_upload">\n            <div id="imgdiv" style="display:none;">\n\n            <\/div>\n            \n        <\/form>\n        <!--\u4e0b\u8f7d\u56fe\u7247-->\n        <button value="\u4e0b\u8f7d\u56fe\u7247" onclick="download()">\u4e0b\u8f7d\u56fe\u7247<\/button>\n        <!--JS\u90e8\u5206-->\n       <script type="text\/java<\/a> script">\n         \n        \/\/\u9875\u9762\u7684\u521d\u59cb\u5316\n        $(function () {\n            $("#file_upload").uploadify({       \/\/\u7ed1\u5b9a\u5143\u7d20      \n            'fileObjName':'image',\/\/html input\u6807\u7b7e\u7684name\u5c5e\u6027\u7684\u503c\u5427\u3002                 \n            'debug':false,                  \n            'auto':true,    \/\/\u81ea\u52a8\u4e0a\u4f20 \n            'multi':true,\n            'removeCompleted':false, \/\/\u4e0a\u4f20\u5b8c\u6210\u4ee5\u540e\u662f\u5426\u4fdd\u5b58\u8fdb\u5ea6\u6761            \n            'buttonText':'\u9009\u62e9\u6587\u4ef6',                                     \n            'cancelImg':'\/static\/uploadify\/uploadify-cancel.png',                   \n            'swf':'\/static\/uploadify\/uploadify.swf', \/\/\u5fc5\u987b\u8bbe\u7f6e  swf\u6587\u4ef6\u8def\u5f84             \n            'uploader':'\/home\/fileuplaod',         \/\/\u5fc5\u987b\u8bbe\u7f6e\uff0c\u4e0a\u4f20\u6587\u4ef6\u89e6\u53d1\u7684url       \n            'fileTypeDesc':'FileType',                  \n            'fileTypeExts':'*.jpg;*.jpge;*.gif;*.png;',          \n            'multi':true,  \n            'onUploadSuccess': function (file, data, response) {\n               $("#imgdiv"","orderid":"0","title":"Gin-Go\u5b66\u4e60\u7b14\u8bb0\u56db\uff1aGin-Web\u6846\u67b6 \u6587\u4ef6\u7684\u4e0a\u4f20\u4e0b\u8f7d(\u4e00)","smalltitle":"","mid":"0","fname":"GO","special_id":"0","bak_id":"0","info":"0","hits":"4035","pages":"2","comments":"0","posttime":"2017-12-23 06:06:47","list":"1513980407","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"http:\/\/images2017.cnblogs.com\/blog\/1290422\/201712\/1290422-20171220150646131-1537007443.png","ispic":"1","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"Gin-Go<\/A> \u5b66\u4e60<\/A> \u7b14\u8bb0<\/A> Gin-Web<\/A> \u6846\u67b6<\/A> \u6587\u4ef6<\/A> \u4e0a\u4f20\u4e0b\u8f7d<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"113.110.148.159","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"Gin-Go\u5b66\u4e60\u7b14\u8bb0\u56db\uff1aGin-Web\u6846\u67b6 \u6587\u4ef6\u7684\u4e0a\u4f20\u4e0b\u8f7d","lastview":"1714089648","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}