前台<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="order_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="../jsAutocomplete/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="../uploadify/jquery.uploadify.v2.1.0.min.js" type="text/javascript"></script>
<script src="../uploadify/swfobject.js" type="text/javascript"></script>
<link href="../uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
$("#uploadify").uploadify({
'uploader': '../uploadify/uploadify.swf',
'script': '../uploadify/UploadHandler.ashx',
'cancelImg': '../uploadify/cancel.png',
'folder': 'uploads',
'queueID': 'fileQueue',
'sizeLimit': '5242880', //5M
'auto': false,
'multi': true,
'onError': function(a, b, c, d) {
if (d.status == 404)
alert('Could not find upload script. Use a path relative to: ' + '<?= getcwd() ?>');
else if (d.type === "HTTP")
alert('error ' + d.type + ": " + d.status);
else if (d.type === "File Size")
alert(c.name + ' ' + d.type + ' Limit: ' + Math.round(d.sizeLimit / 1024) + 'KB');
else
alert('error ' + d.type + ": " + d.info);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="fileQueue"></div>
<input type="file" name="uploadify" id="uploadify" />
<a href="javascript:$('#uploadify').uploadifyUpload()">上传</a>|
<a href="javascript:$('#uploadify').uploadifyClearQueue()">取消上传</a>
</div>
</form>
</body>
</html>
后台这样只能把文件拷贝到另一个文件夹中,如何修改才能把文件存入数据库?
谢谢!<%@ WebHandler Language="C#" Class="UploadHandler" %>
using System;
using System.IO;
using System.Net;
using System.Web; public class UploadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
HttpPostedFile oFile = context.Request.Files["Filedata"];
string strUploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"])+"\\";
if (oFile != null)
{
if (!Directory.Exists(strUploadPath))
{
Directory.CreateDirectory(strUploadPath);
}
oFile.SaveAs(strUploadPath + oFile.FileName);
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}
}
public bool IsReusable
{
get { return false; }
}
}
<head runat="server">
<title></title>
<script src="../jsAutocomplete/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="../uploadify/jquery.uploadify.v2.1.0.min.js" type="text/javascript"></script>
<script src="../uploadify/swfobject.js" type="text/javascript"></script>
<link href="../uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function() {
$("#uploadify").uploadify({
'uploader': '../uploadify/uploadify.swf',
'script': '../uploadify/UploadHandler.ashx',
'cancelImg': '../uploadify/cancel.png',
'folder': 'uploads',
'queueID': 'fileQueue',
'sizeLimit': '5242880', //5M
'auto': false,
'multi': true,
'onError': function(a, b, c, d) {
if (d.status == 404)
alert('Could not find upload script. Use a path relative to: ' + '<?= getcwd() ?>');
else if (d.type === "HTTP")
alert('error ' + d.type + ": " + d.status);
else if (d.type === "File Size")
alert(c.name + ' ' + d.type + ' Limit: ' + Math.round(d.sizeLimit / 1024) + 'KB');
else
alert('error ' + d.type + ": " + d.info);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="fileQueue"></div>
<input type="file" name="uploadify" id="uploadify" />
<a href="javascript:$('#uploadify').uploadifyUpload()">上传</a>|
<a href="javascript:$('#uploadify').uploadifyClearQueue()">取消上传</a>
</div>
</form>
</body>
</html>
后台这样只能把文件拷贝到另一个文件夹中,如何修改才能把文件存入数据库?
谢谢!<%@ WebHandler Language="C#" Class="UploadHandler" %>
using System;
using System.IO;
using System.Net;
using System.Web; public class UploadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";
HttpPostedFile oFile = context.Request.Files["Filedata"];
string strUploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"])+"\\";
if (oFile != null)
{
if (!Directory.Exists(strUploadPath))
{
Directory.CreateDirectory(strUploadPath);
}
oFile.SaveAs(strUploadPath + oFile.FileName);
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}
}
public bool IsReusable
{
get { return false; }
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货