string str = UploadUrl;
string ss = str.Substring(str.LastIndexOf("\\") + 1);
string s = System.Web.HttpContext.Current.Server.MapPath("~\\photo\\" + ss);
if (!File.Exists(s))
{
Directory.CreateDirectory(s);
}
System.Web.HttpContext.Current.Request.SaveAs(s,false);
怎么实现这个貌似只创建文件夹
<input type="file" id="upload" name="upload" runat="server"/> <input type="button" id="imgUpload" text="图片上传" runat="server" onclick="upload_click"> 后台cs: upload_click 里面: string uploadName = upload.Value; string pictureName = ""; if (uploadName != "") { string[] arrExtension ={ ".gif", ".jpg", ".bmp", ".png" }; int idx = uploadName.LastIndexOf("."); string suffix = uploadName.Substring(idx);//获得上传的图片的后缀名 if(arrExtension.Contains(suffix) { pictureName = DateTime.Now.Ticks.ToString() + suffix; //加时间作为新的图片名 } } try { if (uploadName != "") { string path = Server.MapPath("~/images/"); upload.PostedFile.SaveAs(path + pictureName); } } catch (Exception ex) { Response.Write(ex); } }
我不再客户端实现实现上传,客户端只做信息的传输,
具体的上传在业务逻辑里处理请问里面大概怎么写
@库子: 那你应该读取传输的内容,然后自己新建一个文件,把内容存进新建的文件中去。
@库子:
前端选中图片,然后图片在业务逻辑里实现,
我能这样理解吗?
可以这样做,在业务逻辑定义个方法,如:
public class Upload{ public bool imgUpload( FileUpload upload) { string uploadName = upload.Value;
string pictureName = "";
if (uploadName != "")
{
string[] arrExtension ={ ".gif", ".jpg", ".bmp", ".png" };
int idx = uploadName.LastIndexOf(".");
string suffix = uploadName.Substring(idx);//获得上传的图片的后缀名
if(arrExtension.Contains(suffix) {
pictureName = DateTime.Now.Ticks.ToString() + suffix; //加时间作为新的图片名
}
}
try {
if (uploadName != "") {
string path = Server.MapPath("~/images/");
upload.PostedFile.SaveAs(path + pictureName);
return true;
}
}
catch (Exception ex) {
return false;
} } }
button_click 里面
Upload up = new Upload()
bool isUpload = up.imgUpload(upload)
@|WinKi|: 呀我脑子一时没转过来都忘了可以把这控件传进去啊
HttpPostedFile file = context.Request.Files["Filedata"];//获取上传的文件数据.
string fileName = Path.GetFileName(file.FileName);//获取上传文件的名称.
string fileExt = Path.GetExtension(fileName);//得到文件的扩展名.
file.SaveAs(context.Server.MapPath("/UploadImage/" + fileName));//把图片保存起来。
HttpPostedFile file = context.Request.Files["Filedata"];
这里面的filedata怎么讲 啊 上传文件的数据?指的是
是这样的我的UI那只做选取图片不做保存,我的上传是在业务里面来处理,当然图片的原始路径啊什么的我都会给传过来