我正在使用dropzone上传图像。图像将被上传到服务器文件夹,而图像名称将被保存在数据库表中。如何使用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 [email protected] where [email protected]
";
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。 – Icewine
列名无所谓! – ace
这里的问题是,如果用户一次上传4张图片。我将如何编写查询n代码来上传这4个图像? string strSql = @“update tablename set image = @ image where id = @ Id – ace