Script:
<script type="text/javascript"> $(document).ready(function () { $("#Button1").click(function (evt) { var fileUpload = $("#FileUpload1").get(0); var files = fileUpload.files; var data = new FormData(); for (var i = 0; i < files.length; i++) { data.append(files[i].name, files[i]); }
//額外的參數
data.append("Key", "Value");
var options = {}; options.url = "FileUploadHandler.ashx"; options.type = "POST"; options.data = data; options.contentType = false; options.processData = false; options.success = function (result) { alert(result); }; options.error = function (err) { alert(err.statusText); }; $.ajax(options); evt.preventDefault(); }); }); </script>
ashx:
public void ProcessRequest(HttpContext context) {
//額外參數
string para1 = context.Request.Params.Get("key") == null ? "" : context.Request.Params.Get("key");
if (context.Request.Files.Count > 0) { HttpFileCollection files = context.Request.Files; for (int i = 0; i < files.Count;i++ ) { HttpPostedFile file = files[i]; string fname = context.Server.MapPath("~/uploads/" + file.FileName); file.SaveAs(fname); } } context.Response.ContentType = "text/plain"; context.Response.Write("File(s) Uploaded Successfully!"); }
請問一下
回覆刪除用這方法上傳檔案
有沒有擋案大小的限制
如果有的話上限是多少
要怎麼讓他沒有上限?