在火狐和IE 下上传的问题
瞎猪 2008-08-01 10:29:12 无JS代码 纯服务器端
上传控件 下面是代码
protected void UploadOK_Click(object sender, ImageClickEventArgs e)
{
string fileContentType = PictureUpload.PostedFile.ContentType;
if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg")
{
string name = PictureUpload.PostedFile.FileName; // 客户端文件路径
FileInfo file = new FileInfo(name);
string fileName = file.Name;
string webFilePath = Server.MapPath("../Photo/" + fileName); // 服务器端文件路径
if (!File.Exists(webFilePath))
{
try
{
Stream stream = PictureUpload.PostedFile.InputStream;
System.Drawing.Image LoadImg = System.Drawing.Image.FromStream(stream);
CommunityGlobal.SaveImg(LoadImg, 800, 600, webFilePath, "HW");//图片缩放的方法
//PictureUpload.SaveAs(webFilePath); //以前是用这个方法上传的 也是有错的
}
catch
{
MessageBox.Show(this, "上传失败");
}
}
else
{
MessageBox.Show(this, "文件已经存在,请重命名后上传");
}
}
else
{
MessageBox.Show(this, "文件类型不符");
}
}