CSWSite/uploadimg.aspx.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CSWSite
{
    public partial class uploadimg : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (this.myFile.PostedFile != null)//上传文件
            {
                if (this.myFile.PostedFile.FileName != "")
                {
                    string photoName1 = myFile.PostedFile.FileName; //获取初始文件名    
                    int i = photoName1.LastIndexOf("."); //取得文件名中最后一个"."的索引    
                    string newext = photoName1.Substring(i).ToLower(); //获取文件扩展名    
                    if (newext == ".aspx" || newext == ".asp" || newext == ".php" || newext == ".jsp" || newext == ".cgi")
                    {
                        Response.Write("文件格式不正确!");
                        Response.End();
                    }
                    DateTime now = DateTime.Now; //获取系统时间    
                    string photoName2 = now.Millisecond.ToString() + "_" + myFile.PostedFile.ContentLength.ToString() + newext; //重新为文件命名,时间毫秒部分+文件大小+扩展名    
                    myFile.PostedFile.SaveAs(Server.MapPath("~/file/" + photoName2)); // 保存文件到路径,用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用""代替

                    this.TextBoxname.Text = "/file/" + photoName2;
                  


                  Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>foo();</script>");
                }
            }
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。