App_Code/UploadFile.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.Security;
using System.Security.Cryptography;

/// <summary>
///UploadFile 的摘要说明
/// </summary>
public class UploadFile
{
    public static string filepath = "~/upload/";
	public  UploadFile()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
    }
    public static void FileUp(FileUpload f, Label lbl,Label lbl_result)
    {
        Boolean fileOk = false;
        if (f.HasFile)
        {
            string fileExtension = Path.GetExtension(f.FileName).ToLower();
            //验证上传文件是否图片格式
            fileOk = IsFile(fileExtension);

            if (fileOk)
            {
                //对上传文件的大小进行检测,限定文件最大不超过8M
                if (f.PostedFile.ContentLength < 8192000)
                {
                    
                    if (Directory.Exists(HttpContext.Current.Server.MapPath(filepath)) == false)//如果不存在就创建file文件夹
                    {
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath(filepath));
                    }
                    string virpath = filepath + CreatePasswordHash(f.FileName, 4) + fileExtension;//这是存到服务器上的虚拟路径
                    string mappath = HttpContext.Current.Server.MapPath(virpath);//转换成服务器上的物理路径
                    f.PostedFile.SaveAs(mappath);//保存附件
                    lbl_result.Text =virpath;  
                    
                }
                else
                {
                    //pic.ImageUrl = "";
                    lbl.Text = "文件大小超出8M!请重新选择!";
                }
            }
            else
            {
                // pic.ImageUrl = "";
                lbl.Text = "要上传的文件类型不对!请重新选择!";
            }
        }
        else
        {
后面还有 58 行代码,购买后查看完整代码

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

AI 解读 AI

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

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