Files
g.hnyhua.cn/Mtxfw.VipSite/Photo_upload.aspx.cs
2026-02-07 15:48:27 +08:00

72 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
namespace Mtxfw.shop._admin
{
public partial class Photo_upload : Mtxfw.Utility.MemberBase
{
public string strQX = "", imgurl = "", imgurl2 = "", imgPath = "";
public Mtxfw.Utility.Config config = new Mtxfw.Utility.Config("");
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!Page.IsPostBack)
{
if (Request.Files["Photo"] != null)
{
string strContentType = Request.Files["Photo"].ContentType.ToLower();
int intContentLength = Request.Files["Photo"].ContentLength;
if (Mtxfw.Utility.Common.hasType(config.webUpType.Split(','), strContentType))
{
if (intContentLength < 102400 * 20)
{
string FileName, FileType, Folders;
Folders = "/Files/grimage/" + Card + "/";
if (!Directory.Exists(HttpContext.Current.Server.MapPath(Folders)))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(Folders));
}
FileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Millisecond.ToString();
FileType = Request.Files["Photo"].FileName.Substring(Request.Files["Photo"].FileName.LastIndexOf(".")).ToLower();
string strFilePath = Folders + FileName + FileType;
Request.Files["Photo"].SaveAs(Server.MapPath(strFilePath));
try
{
if (!Mtxfw.Utility.Common.IsAllowedExtension(Server.MapPath(strFilePath)))
{
File.Delete(Server.MapPath(strFilePath));
}
else
{
imgurl = Folders + FileName + FileType + "|" + Mtxfw.Utility.Common.GetCoverPic(Folders + FileName + FileType, "100x100", "cut");
}
}
catch
{
File.Delete(Server.MapPath(strFilePath));
}
}
else
{
imgurl = "1";
}
}
else
{
imgurl = "0";
}
}
}
}
}
}