Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "UpLoad.aspx.cs" inherits= "Uploadifydemo_upload"%>
<title>jquery uploadify upload with progress bar, and multiple parameters </title>
<link href= "Js/jquery.uploadify-v2.1.4/uploadify.css" rel= "stylesheet" type= "Text/css"/>
<script type= "Text/javascript" src= "Js/jquery.uploadify-v2.1.4/jquery-1.4.2.min.js" ></script>
<script type= "Text/javascript" src= "Js/jquery.uploadify-v2.1.4/swfobject.js" ></script>
<script type= "Text/javascript" src= "Js/jquery.uploadify-v2.1.4/jquery.uploadify.v2.1.4.min.js" ></script >
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("#uploadify"). Uploadify ({
' Uploader ': ' js/jquery.uploadify-v2.1.4/uploadify.swf ',//uploadify.swf file path
' Script ': ' uploadhandler.ashx ',//process file upload background script path
' cancelimg ': ' Js/jquery.uploadify-v2.1.4/cancel.png ',
' Folder ': ' uploadfile/<% = DateTime.Now.ToString ("yyyyMMdd")%> ',//Upload folder path Press 20130416
' Queueid ': ' Filequeue ', the ID of the element you want to use as a file queue in the page
' Auto ': false,///When the file is added to the queue, automatically uploaded
' Multi ': true,//set to True will allow multiple file uploads
' Fileext ': ' *.jpg;*.gif;*.png ',//allow uploaded file suffix
' Filedesc ': ' Web Image Files (. Jpg. Gif. PNG) ',//text displayed in the file type Drop-down menu at the bottom of the browsing window
' SizeLimit ': 102400,//upload file size limit, Unit bytes 100k
' Onallcomplete ': function (event, data) {///when all files in the upload queue are uploaded, triggered
Alert (data.filesuploaded + ' file upload succeeded! ');
}
});
});
function Uploadpara () {
Custom Pass Parameters
$ (' #uploadify '). Uploadifysettings (' Scriptdata ', {' name ': $ (' #txtName '). Val (), ' albums ': $ (' #txtAlbums '). Val ()});
$ (' #uploadify '). Uploadifyupload ();
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
User name: <asp:textbox id= "txtname" runat= "Server" ></asp:TextBox><br/>
Album Name: <asp:textbox id= "txtalbums" runat= "Server" ></asp:TextBox>
</div>
</form>
<div id= "Filequeue" ></div>
<input type= "File" Name= "uploadify" id= "Uploadify"/>
<p>
<a href= "javascript:void (0);" onclick= "Uploadpara ();" > Upload </a>|
<a href= "javascript:$ (' #uploadify '). Uploadifyclearqueue ()" > Cancel upload </a>
</p>
</body>
Copy Code code as follows:
<%@ WebHandler language= "C #" class= "Uploadhandler"%>
Using System;
Using System.Web;
Using System.IO;
<summary>
Uploadhandler File Upload
</summary>
public class Uploadhandler:ihttphandler
{
public void ProcessRequest (HttpContext context)
{
Context. Response.ContentType = "Text/plain";
Context. Response.Charset = "Utf-8";
Httppostedfile file = context. request.files["Filedata"];
String uploadpath = HttpContext.Current.Server.MapPath (@context. request["folder"]);
String name = Context. request.params["Name"]; Gets the parameters passed
String albums = Context. request.params["albums"];
if (file!= null)
{
if (! Directory.Exists (Uploadpath))
{
Directory.CreateDirectory (Uploadpath);
}
File. SaveAs (Path.Combine, Uploadpath, file. FileName));
Context. Response.Write ("1");
}
Else
{
Context. Response.Write ("0");
}
}
public bool IsReusable
{
Get
{
return false;
}
}
}