【发布时间】:2017-10-29 07:40:26
【问题描述】:
我正在使用 dropzone 上传图片。图片将上传到服务器文件夹,图片名称将保存在数据库表中。
这是我的代码:
公共类 FormUploader_dz : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string dirFullPath = HttpContext.Current.Server.MapPath("/images/");
string[] files;
int numFiles;
files = System.IO.Directory.GetFiles(dirFullPath);
numFiles = files.Length;
numFiles = numFiles + 1;
string str_image = "";
foreach (string s in context.Request.Files)
{
HttpPostedFile file = context.Request.Files[s];
// int fileSizeInBytes = file.ContentLength;
string fileName = file.FileName;
string fileExtension = file.ContentType;
if (!string.IsNullOrEmpty(fileName))
{
fileExtension = System.IO.Path.GetExtension(fileName);
str_image = "MyPHOTO_" + numFiles.ToString() + fileExtension;
string pathToSave_100 = HttpContext.Current.Server.MapPath("/images/") + str_image;
file.SaveAs(pathToSave_100);
Service.SaveImage(strFileName, context.Session["Id"].ToString());
}
}
context.Response.Write(str_image);
}
public bool IsReusable
{
get
{
return false;
}
}
}
服务文件代码:将图像名称插入表中。
public static void SaveImage(string strImage, string Id)
{
string strSql = @"update tablename set image=@image where id=@Id
";
SqlParameter[] objSqlParameter ={
new SqlParameter("@image",strImage),
new SqlParameter("@Id",Id)
};
SqlHelper.ExecuteNonQuery(strConnectionString, CommandType.Text, strSql, objSqlParameter);
}
现在这里的问题是我在表中有 4 列来保存 4 个不同的图像名称。我实际上在做的是允许用户上传最多 4 张图片。我有 4 列,分别是 img1、img2、img3、img4。
这里如何将图像名称插入/更新到表中,因为它们是 4 个不同的图像列! 在这里,如果用户想要他可以上传 4 张图片。那么如何确定图像名称将放在哪一列????
有什么建议吗??????
【问题讨论】:
-
哪一栏重要吗?如果不是,您可以像循环一样按顺序执行,每次递增 1。
-
列名无关紧要!
-
这里的问题是如果用户一次上传 4 张图片。我将如何编写查询代码来上传这 4 张图片? string strSql = @"更新表名 set image=@image where id=@Id
标签: c# asp.net sql-server image dropzone.js