📄 upfile.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using Bestcomy.Web.Controls.Upload;
using Club.Framework;
using Club.Framework.Components;
using Club.Framework.Configuration;
using Club.Framework.Data;
namespace Club.ClubManage
{
/// <summary>
/// upFile 的摘要说明。
/// </summary>
public class upFile : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btn;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Panel Panel2;
protected int RegisterId
{
get
{
if(FormSecurity.GetAdminLoginId()!=0)
{
return FormSecurity.GetAdminLoginId();
}
return FormSecurity.GetMemberId();
}
}
private c_UserDataCountInfo userDataCount;
public c_UserDataCountInfo UserDataCount
{
get
{
return this.userDataCount;
}
}
private c_HomeSettingInfo setting;
public c_HomeSettingInfo Setting
{
get
{
return this.setting;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!FormSecurity.IsAuthenticated())
{
throw new AdminException("对不起,您没有登陆不能使用此功能!",Globals.UrlFormats.Home());
}
AspnetUpload upldr = new AspnetUpload();
string fpath =Globals.GetFilePath(Config.ClubPhotoCache);
if(!Directory.Exists(fpath))
Directory.CreateDirectory(fpath);
upldr.set_UploadFolder(fpath);
//upldr.set_MaxRequestLength(Config.Settings.UpImageMaxLength);//KB;
if(this.Request.QueryString["Show"]=="False")
{
this.Panel1.Visible=false;
this.Panel2.Visible=true;
}
else
{
this.Panel1.Visible=true;
this.Panel2.Visible=false;
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btn.Click += new System.EventHandler(this.btn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btn_Click(object sender, System.EventArgs e)
{
this.userDataCount = Globals.DbProvider.GetUserCountInfo(this.RegisterId);
this.setting=Globals.DbProvider.Select_c_HomeSettingByRegisterID(this.RegisterId);
if(this.setting==null)
{
this.setting=new c_HomeSettingInfo();
}
string photoPath=Globals.GetFilePath(Config.ClubPhotoPath);
string photoSPath=Globals.GetFilePath(Config.ClubSPhotoPath);
string photoUrl=Globals.GetWebPath(Config.ClubSPhotoPath);
if(Config.Settings.UpFileIsMakeDir)
{
photoPath=photoPath+this.RegisterId+"\\";
photoSPath=photoSPath+this.RegisterId+"\\";
photoUrl =photoUrl+this.RegisterId+"/";
FileHelper.AddFolder(photoPath);
FileHelper.AddFolder(photoSPath);
}
string filename=string.Empty;
UploadFile file =AspnetUpload.GetUploadFile("file1");
filename=StringHelper.GetDataRandom();
string ex_Name=StringHelper.GetLastStr(Path.GetFileName(file.get_FileName()),".");
long fileLength=file.get_ContentLength();
filename=filename+"."+ex_Name;
file.SaveAs(photoPath+filename);
if((this.userDataCount.UseCapabilitySize+fileLength)/1048576.0>this.setting.CapabilitySize)
{
Page.RegisterClientScriptBlock("showMsg",Globals.Javascript.getScriptContent("alert('你的个人空间已满,请升级空间或删除一些图片或音乐!');parent.window.close();"));
FileHelper.DelFileExe(photoPath+filename);
return ;
}
if(StringHelper.GetStrCount("gif,jpeg,png,jpg,bmp",ex_Name.ToLower().Trim())==0)
{
Page.RegisterClientScriptBlock("showMsg",Globals.Javascript.getScriptContent("alert('请上传gif,jpeg,png,jpg,bmp格式的图片!');parent.window.close();"));
FileHelper.DelFileExe(photoPath+filename);
return ;
}
if(fileLength>(Config.Settings.UpImageMaxLength*1024))
{
Page.RegisterClientScriptBlock("showMsg",Globals.Javascript.getScriptContent("alert('请上传小于"+Config.Settings.UpImageMaxLength+"KB的图片!');parent.window.close();"));
FileHelper.DelFileExe(photoPath+filename);
return ;
}
ImageHelper image=new ImageHelper();
image.SourcePath= photoPath+filename;
image.SavePath = photoSPath + filename;
image.MakeAlbumImages(100,100);
string scriptString=Globals.Javascript.getScriptContent("upFileFinish('"+filename+"')");
Page.RegisterClientScriptBlock("returnValue",scriptString);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -