关于上传(上传所用到的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);
}
}
}