今天在网上找了一天,想要找到一个比较全的使用案例,结果发现基本上全是一个版本的。。。
我的问题主要是上传完成后,还需要将路径获取到,然后保存到数据库。
查了一下资料发现有这么一个参数onComplete,然后就想明白了。
话不多,开始code
<link rel="Stylesheet" href="js/uploadify.css" /> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/swfobject.js"></script> <script type="text/javascript" src="js/jquery.uploadify.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#uploadify").uploadify({ 'uploader': 'js/uploadify.swf', 'script': 'UploadFile.ashx', 'cancelImg': 'js/cancel.png', 'folder': 'upload', 'queueID': 'fileQueue', 'auto': true, 'multi': true, 'buttonText': '', 'buttonImg':'js/browseBtn.png', 'height':'25', 'wmode':'transparent', 'onComplete':function (event, queueId, fileObj, response, data) { //可以用隐藏域隐藏起来 $('<li></li>').appendTo('.files').text(response); }, }); }); </script> //页面正文内容 <input type="file" name="uploadify" id="uploadify" /> <%--<a href="javascript:$('#uploadify').uploadifyUpload()">上传</a>| <a href="javascript:$('#uploadify').uploadifyClearQueue()"> 取消上传</a>--%>
<div id="fileQueue"></div> <div class="files"></div>
pptuEnH885//jJKSEhFrtrq/+93vullgbpdf+DncJwaqv9KX5WfAuC++LvUBZJDYsDBovpvDEnS4Y+9TBx7uQ/jFDIBvAVlE+BnMRjbx3FEenN+OxcGfLWbAgQq7JxzM8Bl5sPZ99c0fCz+LrW/+2Ni4nH766bjnnnvkPT2vf56ikUg4pCz/McMtX0DAxvzvLt/+0QuvijME4Jch/M8ZrNbpf7v/UQOmX0DZzQDe8yWAn7vcwwA+ouv6E19icdiFMXvE4CAoMfAFqo1k0tl950yS8SU+fRZOa26neivV2ziCZO47N8jh4/0jVxVWBJO6qTlQ8vx3MMxfhOL4u/gPXR3VXB1mJuJU1M+Mj+B4iVb2kylVk18v4ZX2l3nh/kxtV1445/LR8Yn1J3fcaBLzLkZeXnjQ4CqMnTQOA6sqUVBYIOi7mmAvR/XZO8Lt+p43U/41f/byWe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CdLS3v4gBpDBintHYSEZGFJz5p4sjH3k4lSalknrq/203huiEy3N3cTdIeSQ8gNZB1Jjh252CkkHRjwAuRKATigPxIACsBuQOddHy0t3al0A9kprarkAq9bXL5p6/QLJ7b4bAfmJdBWqUj9ccb18sAdeVn1nwGCpLRu5HWl54GkMYELZBS1uiyhrrOY6aAnaonKbNO79pjXEeDLwmXaTBEWbsjCpkTOAlD6x0CXHlcXXCOtd4IW8GtRkrawAVGA6ZheIajNSHoB+jlnzdi7ofWTstEOMSPcEzPvlUY55PmC26x09IC0POMfbrpbt2ramNg4xgI5YWZ2O8MRYQPVUnN7p5Nyb7PDgk2bn/yhaUvlBssbPCwtdY30kWvW+j46u95Eg76P9gQDqc9dQH+ecvs/JYA+hXZ/l8/+jHU8kzildopW9OPsSYsqnJX+InqHtTH2bZmkwePO6kzftrnvYuYr/ZucOrxzqz8gOpe/9/Xpf7ciwSGwbs8OCTyfOLX2B05r/JcAA6GDp3diucg0AAAAASUVORK5CYII=" alt="" />从网上找的图片,挺好看的,大家可以试试。
后台UploadFile.ashx文件中
HttpPostedFile file = context.Request.Files["FileData"]; string uploadpath = context.Server.MapPath(context.Request["folder"] + "\\"); if (file != null) { if (!Directory.Exists(uploadpath)) { Directory.CreateDirectory(uploadpath); } file.SaveAs(uploadpath + file.FileName);
//在这里将文件保存的路径返回到页面 context.Response.Write(uploadpath + file.FileName); } else { context.Response.Write("0"); }
在处理程序中也可以返回自定义的json,前台onComplete事件中通过参数response接收到数据,解析,然后使用jquery将路径保存到隐藏域里面,在提交保存时,通过隐藏域对象获取到路径就ok了
我也是初次使用,大家要有好的建议可以一起讨论。
附上自己写的小demo:点击这里下载...