看看这个吧,很简单:
http://www.cnblogs.com/chenkai/archive/2013/01/04/2844702.html
获取路径呀,一个input标签,一个file类型,一个javascript获取,然后传值
预览代码:
<script language=JavaScript>
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 120/80){
if(image.width>120){
ImgD.width=120;
ImgD.height=(image.height*120)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>80){
ImgD.height=80;
ImgD.width=(image.width*80)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
/**//*else{
ImgD.src="";
ImgD.alt=""
}*/
}
function FileChange(Value){
flag=false;
document.all.uploadimage.width=10;
document.all.uploadimage.height=10;
document.all.uploadimage.alt="";
document.all.uploadimage.src=Value;
}
function BeforeUpLoad(){
if(flag) alert("OK");else alert("FAIL");
}
</script>
<INPUT style="WIDTH: 143px; HEIGHT: 18px" type=file size=8 name=pic onchange="javascript:FileChange(this.value);">
<IMG id=uploadimage height=10 width=10 src="" onload="javascript:DrawImage(this);" ><BR>
<Button onclick="javascript:BeforeUpLoad();">提交</Button>
在Winform里添加:
上传图片: <asp:FileUpload ID="fileUploadImage" runat="server" CssClass="file_upload_300" /> 图片名: <asp:Button ID="btnUpload" runat="server" Text="上传" CssClass="btn" onclick="btnUpload_Click" ToolTip="只接受JPG文件,单张大小不超过2M" />
<asp:Label ID="lblMsg" runat="server" Text="" CssClass="msg_error"></asp:Label>
<asp:Image ID="Image1" runat="server" />
后台:
protected void btnUpload_Click(object sender, EventArgs e) { try { lblMsg.Text = ""; savePicture("imgpic"); } catch (Exception ex) { lblMsg.Text = ex.Message; } }
// 保存图片 protected void savePicture(string name) { if (!fileUploadImage.HasFile) { lblMsg.Text = "请选择文件!"; return; } string filepath = "", fileExtName = "", mFileName, mPath; filepath = fileUploadImage.PostedFile.FileName; fileExtName = filepath.Substring(filepath.LastIndexOf(".") + 1); if (fileExtName.ToLower() != "jpg" && fileExtName.ToLower() != "jpeg") { lblMsg.Text = "请选择JPG文件!"; return; } mPath = Server.MapPath("img\\"); mFileName = name + ".jpg"; fileUploadImage.PostedFile.SaveAs(mPath + mFileName);
Image1.ImageUrl = "img/" + mFileName; }