上传浏览框

<input  id="file1" runat="server" class="inputBox" style="width: 289px" type="file" />

 

cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class hr_member_Perpic : System.Web.UI.Page
{
protected string imgurl;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["id"] != null && Session["id"] != "")
{
if (Session["id"] == null)
{
Response.Write(
"Read ID error");
Response.Redirect(
"/hr/login.aspx");
}
if (!Page.IsPostBack)
{
Image1.ImageUrl
= "~/HR/" + Session["PIC"].ToString();
}
}
else
{
Response.Write(
"<script>alert('请重新登陆!');self.location='/hr/login.aspx';</script>");
}

}



protected void Button1_Click(object sender, EventArgs e)
{
string res,SQL;
upload up
= new upload();
res
= up.Up(file1, "../UploadFile/");
this.Label1.Visible = true;
this.Label1.Text = up.Resup[Convert.ToInt32(res)];
this.pic.Text = up.Jobs;
Session.Add(
"PIC", up.Jobs);
Image1.ImageUrl
= "~/HR/" + Session["PIC"].ToString();

SQL
= "update Job_Person set pic='" + up.Jobs + "' where id='" + Session["id"].ToString() + "'";
SqlData sd
= new SqlData();
sd.ExceSQL(SQL);

}
}

 

upload类
using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// upload 的摘要说明
/// </summary>
public class upload
{
public upload()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string[] Resup ={ "上传失败或指定的文件不存在", "图片大于200K,重新传图片!", "格式不对,限制上传(只允许gif/jpg格式文件)!", "上传成功!" };
public string s = string.Empty;
public string Jobs = string.Empty;
public string Up(System.Web.UI.HtmlControls.HtmlInputFile File2, string Pa)
{
//
// TODO: 在此处添加构造函数逻辑
//

if (File2.PostedFile.ContentLength.ToString() == "0")
{
return "0";
}
else
{
//获取文件名称
string ss;
ss
= System.DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + Path.GetExtension(File2.PostedFile.FileName);
if (File2.PostedFile.ContentLength / 1024 > 200)
{
return "1"; }
else
{
string ty = File2.PostedFile.ContentType;
if (ty == "image/gif" || ty == "image/pjpeg")
{
File2.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath(Pa)
+ ss);
s
= "/manager/Uploads/" + ss;
Jobs
= "UploadFile/" + ss;
return "3";
//Up= ss;
}
else
{
return "2"; }
}
}

}
}

转载于:https://www.cnblogs.com/server/archive/2008/11/01/1324160.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值