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 ={ "上传失败或指定的文件不存在", "图片大于1M，重新传图片！", "格式不对，限制上传（只允许gif/jpg格式文件）！", "上传成功！" };
    public string s = string.Empty;

    public string Up(System.Web.UI.HtmlControls.HtmlInputFile File2, string Pa)
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //

        if (File2.PostedFile.ContentLength.ToString() == "0")
        {
            return "0";
        }
        else
        {
            string filepath = File2.PostedFile.FileName;
            string name = filepath.Substring(filepath.LastIndexOf("\\") + 1);//获取文件名
            string Extend = filepath.Substring(filepath.LastIndexOf(".") + 1);//获取格式名
            //获取文件名称name.Substring(0,name.Length-Extend.Length-1)
            string ss;
            ss = System.DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "").Replace("/","") + Path.GetExtension(File2.PostedFile.FileName);
            if (File2.PostedFile.ContentLength / 1024 > 30024)
            { return "1"; }
            else
            {
                string ty = File2.PostedFile.ContentType;
                if (ty == "image/gif" || ty == "image/pjpeg"||ty=="application/octet-stream"|| ty=="application/vnd.ms-powerpoint" ||ty=="application/vnd.openxmlformats-officedocument.presentationml.presentation" || ty == "application/pdf" || ty == "application/msword" || ty == "application/vnd.ms-excel")
                {
                    File2.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath(Pa) + ss);
                    s = "Uploads/" + ss;
                    return "3";
                    //Up= ss;
                }
                else
                { return "2"; }
            }
        }

    }
}
