62,074
社区成员
发帖
与我相关
我的任务
分享
Boolean fileOK = false;
String path = Server.MapPath("photo");
if (PhotoFul.HasFile) //判断是否有图片传上来了
{
String fileExtension =
System.IO.Path.GetExtension(PhotoFul.FileName).ToLower();//获取文件扩展名
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg", ".bmp" }; //允许上传的文件格式
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
break;
}
}
if (fileOK)
{
try
{
PhotoFul.PostedFile.SaveAs(path + "\\" + PhotoFul.FileName);
PhotoImg.Visible = true;
float newwt, newht;
int oldwt = matic.toint(PhotoImg.Width.ToString());
int oldht = matic.toint(PhotoImg.Height.ToString());
matic.ChangPictur(PhotoFul.PostedFile.FileName, out newwt, out newht, oldwt, oldht);
//matic.ChangPictur("photo/" + PhotoFul.FileName, out newwt, out newht, oldwt, oldht);
this.PhotoImg.Width = 322;
this.PhotoImg.Height = 322;
PhotoImg.Height = (int)newht;
PhotoImg.Width = (int)newwt;
PhotoImg.ImageUrl = "photo" + "\\" + PhotoFul.FileName;
PhotoLab.Text = "上传图片成功";
this.PhotoImg.AlternateText = "无法显示图片";
}
catch (Exception ex)
{
Response.Write("<script>PhotoLab.ForeColor = 'Red';</script>");
PhotoLab.Text = "ERROR: " + ex.Message.ToString();
}
finally { }
}
else
{
PhotoLab.Text = "文件的类型不合适";
}
}
else
{
PhotoLab.Text = "没有图片上传";
}
var isIE = (document.all) ? true : false;
var isIE7 = isIE && (navigator.userAgent.indexOf('MSIE 7.0') != -1);
var isIE8 = isIE && (navigator.userAgent.indexOf('MSIE 8.0') != -1);
var isMozilla = /mozilla/.test( navigator.userAgent ) && !/(compatible|webkit)/.test( navigator.userAgent );
var isOpera = /Opera/.test( navigator.userAgent );
var thehid=document.getElementById("hidthepath");
if(isIE7 || isIE8){
thehid.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='hidden')"
}
function GetThePath()
{
var thefile=document.getElementById("你的文件控件");
var thepath=thefile.value;
if(isIE7 || isIE8){
thefile.select();
var thepath=document.selection.createRange().text;
document.selection.empty();
}else if(isMozilla){
thepath = thefile.files[0].getAsDataURL();
}
document.getElementById('你的隐藏字段').value=thepath;
//alert(document.getElementById('你的隐藏字段').value);
}