2012. 1. 6. 23:36
1. Uploadify.htm
2. Uploadify.ashx
}
<head>
<title>파일업로드 : jQuery + Uploadify + ASP.NET</title>
<link href="uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/ecmascript" src="jquery-1.4.2.min.js"></script>
<script src="jquery.uploadify.v2.1.4.js" type="text/javascript"></script>
<script src="swfobject.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
// Uploadify 파일 업로드 컨트롤 : Flash가 설치가 되어있어야 함
$('#fileInput').uploadify({
'uploader': 'uploadify.swf', // Uploadify 컨트롤 지정
'script': 'Uploadify.ashx', // 서버측 스크립트, ASP.NET, ASP, PHP, JSP
'cancelImg': 'cancel.png', // 취소 이미지
'auto': false, // true면 파일선택시 바로 자동으로 업로드됨
'folder': '/Uploads', // 업로드할 폴더 : 가상디렉터리 + 업로드폴더
// 업로드 완료시 처리 :
// 주요 속성은 http://www.uploadify.com/documentation/ 참고
'onComplete': function (event, queueID, fileObj, response, data) {
$('#lblFile').append('<a href=/WebJQuery' + fileObj.filePath + '>'
+ fileObj.name + '</a><br>');
}
});
// 버튼 클릭시 업로드
$('#btn').click(function () { $('#fileInput').uploadifyUpload(); });
});
</script>
</head>
<body>
<input id="fileInput" name="fileInput" type="file" />
<input type="button" id="btn" value="업로드" />
<div id="lblFile"></div>
</body>
</html>2. Uploadify.ashx
<%@ WebHandler Language="C#" Class="Uploadify" %>
using System;
using System.Web;
public class Uploadify : IHttpHandler {
public void ProcessRequest (HttpContext context) {
// Filedata로 넘겨온 파일 값 받기
HttpPostedFile file = context.Request.Files["Filedata"];
// 저장할 폴더
string targetDirectory = System.IO.Path.Combine(
context.Request.PhysicalApplicationPath,
context.Request["folder"].Replace("/", ""));
// 저장할 폴더 + 파일명
string targetFilePath = System.IO.Path.Combine(
targetDirectory, file.FileName);
// 파일 저장(업로드)
file.SaveAs(targetFilePath);
context.Response.Write("RedPlus");
}
public bool IsReusable {
get {
return false;
}
}
'PP > Upload' 카테고리의 다른 글
실시간 파일 업로드 - uploadify (0) | 2012.01.04 |
---|