问题陈述:我要通过点击
<input id="loFile" type="file" size="25"runat="server" height="100">浏览,后弹出的对框中,只显示图片文件
望高手指点,
最好是给点代码,谢谢
<input id="loFile" type="file" size="25"runat="server" height="100">浏览,后弹出的对框中,只显示图片文件
望高手指点,
最好是给点代码,谢谢
解决方案 »
- asp.netImageButton1_Click事件里获取不到被js更改input的值
- 【求助】将网站部署的IIS后,路径出错
- 高分悬赏 .net 2.0角色管理全过程
- |M| 第二贴:300分求:网页Repeater布局显示隐藏的问题
- 请教我不明白,exec用法 ChaXuLei.ShuJuChanXun ("exec 资质等级查询 '"+this.Zhi.Text .Trim ()+"'")
- 传递datagrid中的数据(在线等待........!)
- 为什么VS.NET2003不能新建项目?
- sql 2005插入的问题
- 绝对值得研究的SQL问题!
- 如何用script 在一个<table>内插入一个<tr>,然后再在<tr>内插入一个<td>,大家帮帮忙吧。谢谢!
- C#如何获取IE的语言版本?
- 急救!!!GDI+ 中发生一般性错误, 请大虾们指点!
不是图片文件,则返回false并提示
function check(obj)
{
var path = obj.value;
var fileType = path.substring(path.lastIndexOf('.'),path.length).toUpperCase();
if(fileType!=".JPG" && fileType!=".GIF" && fileType!=".BMP")
alert(fileType + " is not a type of image");
else
document.getElementById("Image1").src = path;
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Image id="Image1" runat="server"></asp:Image>
<INPUT id="File1" type="file" name="File1" runat="server" onchange="check(this);">
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>
</body>
if(inputFile.PostedFile.ContentLength > 0)
{
//设定上传文件的保存路径
string strSaveDir = "images/";
string strName = inputFile.PostedFile.FileName;
//取得文件名(抱括路径)里最后一个"."的索引
int intExt = strName.LastIndexOf(".");
//取得文件扩展名
string strExt = strName.Substring(intExt);
strExt = strExt.ToLower();
if((strExt==".jpg") ||( strExt==".jpeg") || (strExt==".gif"))
{
//这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复
if((inputFile.PostedFile.ContentLength / 1024) >60)
{
Response.Write("<script>alert('图片大小不能超过100K!');</script>");
return;
}
DateTime datNow = DateTime.Now;
string strNewName = datNow.Year.ToString() +datNow.Month.ToString()+datNow.Day.ToString()+datNow.Hour.ToString()+datNow.Minute.ToString()+datNow.Second.ToString() ;
strNewName=strNewName+strExt; //取得文件名(包括路径)里最后一个"\"的索引
int intPath = strName.LastIndexOf("\\"); //取得文件名(不包括路径)
//string strNewName = strName.Substring(intPath);
inputFile.PostedFile.SaveAs(Server.MapPath(strSaveDir + strNewName));
//得到这个文件的相关属性:文件名,文件类型,文件大小
Response.Write("<script>alert('上传成功!');</script>");
Session["IsLoad"] = true;
Session["pic"] = strNewName;
//labelFileExt.Text = "文件类型:" + inputFile.PostedFile.ContentType + "( " + strExt + " )";
//labelFileSize.Text = "文件大小:" + (inputFile.PostedFile.ContentLength / 1024).ToString() + " K Byte(s)"; }
else
{
Response.Write("<script>alert('只能上传格式为:jpg,jpeg,gif 的图片!');location.href=\"liveshow_add.aspx\";</script>");
}
}
else
{
Response.Write("<script>alert('请选择要上传的图片!');</script>");
}