Jquery Uploadify multi-file upload with progress bar and passing your own parameter example

Source: Internet
Author: User

[Html]
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "UpLoad. aspx. cs" Inherits = "UploadifyDemo_UpLoad" %>
 
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Title> Jquery Uploadify uploads a progress bar with 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 ({
'Upload': 'js/jquery. uploadify-v2.1.4/uploadify.swf ', // path of the uploadify.swf File
'Script': 'uploadhandler. ashx', // path of the background script for processing file uploads
'Cancelim': 'js/jquery. uploadify-v2.1.4/cancel.png ',
'Folder': 'uploadfile/<% = DateTime. Now. ToString ("yyyyMMdd") %> ', // press 20130416
'Queueid': 'filequeue ', // id of the element you want to use as a file queue on the page
'Auto': false, // automatic upload when a file is added to the queue
'Multi ': true, // if it is set to true, multi-File Upload is allowed.
'Fileext ':' *. jpg; *. gif; *. png ', // specifies the suffix of the file to be uploaded.
'Filedesc': 'web Image Files (. JPG,. GIF,. PNG) ', // text displayed in the file type drop-down menu at the bottom of the browser window
'Sizelimmit ': 102400, // size limit of the file to be uploaded, measured in 100 KB
'Onallcomplete': function (event, data) {// triggered when all files in the upload queue are uploaded
Alert (data. filesUploaded + 'files uploaded successfully! ');
}
});
});
 
Function uploadpara (){
// Custom Transfer Parameters
$ ('# Uploadify '). uploadifySettings ('scriptdata', {'name': $ ('# txtName '). val (), 'alums': $ ('# txtalbums '). val ()});
$ ('# Uploadify'). uploadifyUpload ();
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
Username: <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>
</Html>

<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "UpLoad. aspx. cs" Inherits = "UploadifyDemo_UpLoad" %>

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Title> Jquery Uploadify uploads a progress bar with 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 ({
'Upload': 'js/jquery. uploadify-v2.1.4/uploadify.swf ', // path of the uploadify.swf File
'Script': 'uploadhandler. ashx', // path of the background script for processing file uploads
'Cancelim': 'js/jquery. uploadify-v2.1.4/cancel.png ',
'Folder': 'uploadfile/<% = DateTime. Now. ToString ("yyyyMMdd") %> ', // press 20130416
'Queueid': 'filequeue ', // id of the element you want to use as a file queue on the page
'Auto': false, // automatic upload when a file is added to the queue
'Multi ': true, // if it is set to true, multi-File Upload is allowed.
'Fileext ':' *. jpg; *. gif; *. png ', // specifies the suffix of the file to be uploaded.
'Filedesc': 'web Image Files (. JPG,. GIF,. PNG) ', // text displayed in the file type drop-down menu at the bottom of the browser window
'Sizelimmit ': 102400, // size limit of the file to be uploaded, measured in 100 KB
'Onallcomplete': function (event, data) {// triggered when all files in the upload queue are uploaded
Alert (data. filesUploaded + 'files uploaded successfully! ');
}
});
});

Function uploadpara (){
// Custom Transfer Parameters
$ ('# Uploadify '). uploadifySettings ('scriptdata', {'name': $ ('# txtName '). val (), 'alums': $ ('# txtalbums '). val ()});
$ ('# Uploadify'). uploadifyUpload ();
}
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
Username: <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>
</Html>


[Csharp]
<% @ 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"]; // obtain the passed Parameter
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;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.