关于上传(上传所用到的upload和upload的应用)

upload.cs

public class UpLoad
{
    public UpLoad()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }
    public static string Up(FileUpload file2)
    {
        string err = "";
        string fullname = file2.PostedFile.FileName;
        string ty = fullname.Substring(fullname.LastIndexOf(".") + 1).ToLower();
        //if (file2.PostedFile.ContentLength == 0)
        //{
        //    err = "上传失败或指定的文件不存在";
        //}
        if (file2.PostedFile.ContentLength / 1024 > 1024)
        {
            err = "图片大于1M,重新传图片";
        }
        if (ty == "gif" || ty == "pjpeg" || ty == "jpg" || ty == "png" )
        {
            err = "";
        }
        else
        {
            err = "格式不对,限制上传(只允许gif/jpg/png格式文件)";
        }
        return err;
    }

    public static string UpVideo(FileUpload file2)
    {
        string err = "";
        string fullname = file2.PostedFile.FileName;
        string ty = fullname.Substring(fullname.LastIndexOf(".") + 1).ToLower();
        //if (file2.PostedFile.ContentLength == 0)
        //{
        //    err = "上传失败或指定的文件不存在";
        //}
        if (file2.PostedFile.ContentLength / 1024 > 10240)
        {
            err = "视频大于10M,重新传视频";
        }
        if (ty == "wmv" || ty == "mp3" || ty == "wma" || ty == "avi" || ty == "asf" || ty == "mpg"||ty=="swf")
        {
            err = "";
        }
        else
        {
            err = "格式不对,限制上传(只允许wma/mp3/wma/avi/asf/mpg格式文件)";

        }
        return err;
    }
    //进行上传表格和软件

    public static string UpJtnw(FileUpload file2)
    {
        string err = "";
        string fullname = file2.PostedFile.FileName;
        string ty = fullname.Substring(fullname.LastIndexOf(".") + 1).ToLower();
        //if (file2.PostedFile.ContentLength == 0)
        //{
        //    err = "上传失败或指定的文件不存在";
        //}
        if (file2.PostedFile.ContentLength / 1024 > 512000)
        {
            err = "软件大于500M,重新传软件";
        }
        if (ty == "rar" || ty == "zip" || ty == "arj" || ty == "jz" || ty == "z" || ty == "exe")
        {
            err = "";
        }
        else
        {
            err = "格式不对,限制上传(只允许rar/zip/arj/jz/z/exe格式文件)";

        }
        return err;
    }

    public static string UpDoc(FileUpload file2)
    {
        string err = "";
        string fullname = file2.PostedFile.FileName;
        string ty = fullname.Substring(fullname.LastIndexOf(".") + 1).ToLower();
        //if (file2.PostedFile.ContentLength == 0)
        //{
        //    err = "上传失败或指定的文件不存在";
        //}
        if (file2.PostedFile.ContentLength / 1024 > 10240)
        {
            err = "文档大于10M,重新传文档";
        }
        //doc、docx、wps、xls、xlsx、et、ppt、dps、pptx和txt
        if (ty == "doc" || ty == "docx" || ty == "xls" || ty == "xlsx" || ty == "ppt" || ty == "pptx"||ty=="txt"||ty=="wps"||ty=="dps"||ty=="et")
        {
            err = "";
        }
        else
        {
            err = "格式不对,限制上传(只允许doc/docx/wps/xls/xlsx/et/ppt/dps/pptx/txt格式文件)";

        }
        return err;
    }
       public static void Photo(string path)
    {
        if (System.IO.Directory.Exists(path) == false)
        {
            System.IO.Directory.CreateDirectory(path);
        }
    }
}

转载于:https://www.cnblogs.com/licuihua/archive/2013/05/10/3071205.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值