Files
g.hnyhua.cn/Mtxfw.VipSite/Photo_upload2.aspx.cs

87 lines
4.0 KiB
C#
Raw Normal View History

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_upload2 : Mtxfw.Utility.MemberBase
{
public string strQX = "", imgurl = "", imgurl2 = "", imgPath = "", upToken = "";
public Mtxfw.Utility.Config config = new Mtxfw.Utility.Config("");
public int gtype = 0;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Qiniu.Util.Mac mac = new Qiniu.Util.Mac(config.qiniuAccessKey, config.qiniuSecretKey);
Qiniu.Storage.PutPolicy putPolicy = new Qiniu.Storage.PutPolicy();
putPolicy.Scope = config.qiniuScope;
//putPolicy.CallbackUrl = "http://api.example.com/qiniu/upload/callback";
//putPolicy.CallbackBody = "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fsiz\":$(fsize),\"bucket\":\"$(bucket)\",\"name\":\"$(x:name)\"}";
//putPolicy.CallbackBodyType = "application/json";
upToken = Qiniu.Util.Auth.CreateUploadToken(mac, putPolicy.ToJsonString());
if (!Page.IsPostBack)
{
if (IFStores != 1 && MemberuLevel16 != 2)
{
Mtxfw.Utility.Tools.Message("您没有权限!", "/gl.aspx");
}
else
{
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 = config.webUpPath;
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 = FileName + FileType + "|" + Folders + FileName + FileType;
}
}
catch
{
File.Delete(Server.MapPath(strFilePath));
}
}
else
{
imgurl = "1";
}
}
else
{
imgurl = "0";
}
}
}
}
}
}
}