웹 사이트에서 선택한 이미지를 DB에 업로드해야합니다. 내 프로젝트에 여러 개의 파일 선택 "파일 업로드"가 있습니다. 여러 파일을 이진 형식으로 이미지 데이터를 데이터베이스에 업로드하려면 어떻게해야합니까? 내 코드는 내가 로컬 폴더선택한 여러 이미지를 데이터베이스에 업로드하는 방법
<%@ WebHandler Language="C#" Class="Upload" %>
using System;
using System.Web;
using System.IO;
public class Upload : 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 = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
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;
}
}
}
에 파일을 저장하려면 다음 웹 처리기를 사용하고
protected void Button1_Click(object sender, EventArgs e)
{
string Qry = "insert into tblFiles values(@data)";
SqlConnection con = new SqlConnection(@"Data Source=ESLHPC17\SQL2008;Initial Catalog=dbFiles;User ID=user;Password=password");
SqlCommand cmd = new SqlCommand(Qry,con);
cmd.Parameters.Add("@data") = FileUpload1.FileBytes;
}
내가 SCRI 아래를 사용 PT
<script type = "text/javascript">
$(window).load(
function() {
$("#<%=FileUpload1.ClientID%>").fileUpload({
'uploader': 'scripts/uploader.swf',
'cancelImg': 'images/cancel.png',
'buttonText': 'Browse Files',
'script': 'Upload.ashx',
'folder': 'Uploads',
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
'multi': true,
'auto': false
});
하지만 데이터베이스에 이미지를 저장할
나는 아래의 코드를 언급하지만,이 일을하지 않았다으로 시도 Damith@
,
protected void Button1_Click(object sender, EventArgs e)
{
string [email protected]"E:\Rajesh_Kumar\Application\Valuation\ExamManagement\ExamManagement\Uploads";
string path = System.Configuration.ConfigurationManager.AppSettings[FolderPath];
string Qry = "insert into tblFiles values(@data) Values (data)";
SqlConnection con = new SqlConnection(@"Data Source=ESLHPC17\SQL2008;Initial Catalog=dbFiles;User ID=rajesh";
StreamReader sr = new StreamReader(path);
while (sr.ReadLine() != null)
{
using (SqlCommand cmd = new SqlCommand(Qry, con))
{
cmd.Parameters.Add("@data",SqlDbType.VarBinary).Value = path;
con.Open();
cmd.ExecuteNonQuery();
}
con.Close();
con.Dispose();
}
}
당신은 정말 당신의'sa' 비밀번호를 노출 할 수 없습니다. 또한 응용 프로그램이'sa' 사용자로 로그인하지 않아야합니다. –
명령을 실행하면 설정됩니다. 귀하의 질문은 무엇인가? – CodeCaster
@CodeCaster 문제는 그저 하나의 파일 만 처리한다는 것입니다. – LukeHennerley