- Mesajlar
- 1,737
Google’da Uploadify diye aratalım ve http://www.uploadify.com sitesine girelim. Download bölümünden Uploadify-v2.1.4.zip dosyasını indirelim. Bunun içerisindeki php scriptler işimize yaramayacağından silelim. Zip dosyası içerisindek dokümanları projemizin içerisinde uploadify klasörüne kayıt edelim.
Sonra projemizi açalım. Default.aspx e gelelim.
Solution Explorer penceremizde Add New Item diyerek Generic Handler ekleyelim adı Handler.ashx olsun.
Projemizde resimler diye bir klasör oluşturalım. Dosya boyutlarına izin vermek için web.config dosyamızda
ifadesini <system.web> tagının hemen altına yerleştirelim.
Sonra projemizi açalım. Default.aspx e gelelim.
Kod:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Dosya Upload İşlemi</title>
<link href="uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="uploadify/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="uploadify/swfobject.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#file_upload').uploadify({
'uploader': 'uploadify/uploadify.swf',
'script': 'Handler.ashx',
'cancelImg': 'uploadify/cancel.png',
'folder': 'resimler',
'auto': true,
'multi':true,
'fileDesc': 'Image Files',
'fileExt': '*.jpg,*.png,*.gif,*.bmp,*.jpeg'
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="file_upload" name="file_upload" type="file" />
</div>
</form>
</body>
</html>
Solution Explorer penceremizde Add New Item diyerek Generic Handler ekleyelim adı Handler.ashx olsun.
Kod:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.IO;
public class Handler : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Expires = -1;
try
{
HttpPostedFile postedFile = context.Request.Files["Filedata"];
string savepath = "";
string tempPath = "";
tempPath = context.Request["folder"];
savepath = context.Server.MapPath(tempPath);
string filename = postedFile.FileName;
if (!Directory.Exists(savepath))
{
Directory.CreateDirectory(savepath);
}
postedFile.SaveAs(savepath + @"\" + filename);
context.Response.Write(tempPath + "/" + filename);
context.Response.StatusCode = 200;
}
catch (Exception ex)
{
context.Response.Write("Error: " + ex.Message);
}
}
public bool IsReusable {
get {
return false;
}
}
}
Projemizde resimler diye bir klasör oluşturalım. Dosya boyutlarına izin vermek için web.config dosyamızda
Kod:
<httpRuntime maxRequestLength="2097151" executionTimeout="3600"/>
ifadesini <system.web> tagının hemen altına yerleştirelim.