后台是asp的。用input上传图片,怎么传到目标文件夹呢?
看这个示例,有用记得采纳:)。。
asp无惧上传类库
前台通过表达提交,后台通过Request.Files["name"] 获取到图片,在然后调用SaveAs另存在为指定的文件夹就行了。
/*
此代码为Asp.net
*/
//file为你的上传控件
if (file.HasFile)
{
//upload为你要指定的目录
string savePath = Server.MapPath("~/upload/");
//判断目录是否存在
if (!System.IO.Directory.Exists(savePath)) {
System.IO.Directory.CreateDirectory(savePath);
}
//拼接文件路径
savePath = savePath + "\\" + fileUpload.FileName;
//保存文件
file.SaveAs(savePath);
}
/*
此代码为Asp.net
*/
//file为你的上传控件
if (file.HasFile)
{
//upload为你要指定的目录
string savePath = Server.MapPath("~/upload/");
//判断目录是否存在
if (!System.IO.Directory.Exists(savePath)) {
System.IO.Directory.CreateDirectory(savePath);
}
//拼接文件路径
savePath = savePath + "\\" + file.FileName;
//保存文件
file.SaveAs(savePath);
}