Jquery uploadify

Source: Internet
Author: User
Tags file upload httpcontext

I. jquery progress bar code:

<% @ 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">
<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/<% = subpathName %> ', // path of the upload folder
'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
'Oncancel': function (event, ID, fileObj, data) {// triggered once each file is removed from the upload queue
Alert ('The upload of '+ fileObj. name + 'has been canceled! ');
},
'Oncomplete': function (event, ID, fileObj, response, data) {// triggered every time a file is uploaded
Alert ('There are '+ data. fileCount + 'files remaining in the queue .');
},
'Onallcomplete': function (event, data) {// triggered when all files in the upload queue are uploaded
Alert (data. filesUploaded + 'files uploaded successfully! ');
}
});
});
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
</Div>
</Form>

<Div id = "fileQueue"> </div>
<Input type = "file" name = "uploadify" id = "uploadify"/>
<P>
<A href = "javascript: $ ('# uploadify'). uploadifyUpload ()"> Upload </a> |
<A href = "javascript: $ ('# uploadify'). uploadifyClearQueue ()"> cancel Upload </a>
</P>
</Body>
</Html>

2. Back-end program code that generates the jquery progress bar data source:
 
<% @ WebHandler Language = "C #" Class = "UploadHandler" %>
Using System;
Using System. Web;
Using System. IO;
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"]);
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.