migrate to new git

This commit is contained in:
2025-08-29 01:27:25 +08:00
parent 946eb9961e
commit af2c152ef6
8623 changed files with 1000453 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -0,0 +1,421 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="admin_filemanager_index" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>已上傳檔案夾</title>
<link href="~/App_Script/css/admin.css" rel="stylesheet" type="text/css">
<script src="../../App_Script/jquery-1.10.2.js"></script>
<style type="text/css">
html, body {
width:100%;
height:100%;
background-color: #ffffff;
overflow:auto;
}
.picdiv
{
width:140px;
text-align:center;
padding:5px;
float:left;
}
.picdivtd
{
width:132px;
height:132px;
border-style:solid;
border-color:Silver;
border-width:1px;
empty-cells:show;
background-color:White;
padding:0px;
}
</style>
<script type="text/javascript">
<%
if (!string.IsNullOrEmpty(Request["rtnobj"]))
{
string[] rtnobj = Request["rtnobj"].ToString().Split('|');
%>
function OpenFile(fileUrl) {
var myfile=fileUrl.split("/");
var selfile = fileUrl.split(".");
if (selfile[selfile.length-1].toLowerCase()=="jpg" || selfile[selfile.length-1].toLowerCase()=="jpeg" || selfile[selfile.length-1].toLowerCase()=="gif" || selfile[selfile.length-1].toLowerCase()=="png"){
window.opener.document.getElementById("<%=rtnobj[0]%>").value="<%=Request["dirname"] + (!string.IsNullOrEmpty(Request["dirname"])? "/": "")%>" + myfile[myfile.length-1];
window.opener.document.getElementById("<%=rtnobj[1]%>").src="../../App_Script/display.ashx?file=<%=Request["defpath"] %>/<%=Request["dirname"] + (!string.IsNullOrEmpty(Request["dirname"])? "/": "")%>" + myfile[myfile.length-1] + "&w=150&h=150";
window.opener.document.getElementById("<%=rtnobj[1]%>").style.display="block";
window.opener.document.getElementById("<%=rtnobj[2]%>").style.display="block";
window.close();
window.opener.focus();
}else{
alert('請選擇JPG、GIF或PNG圖檔');
}
}
<%
}
else
{
%>
function OpenFile(fileUrl) {
window.opener.CKEDITOR.tools.callFunction(<%= Convert.ToString(Request["CKEditorFuncNum"]) %>, fileUrl);
window.close();
window.opener.focus();
}
<%
}
%>
</script>
<script type="text/javascript">
//---------------------------------checkbox全選用---------------------------------------------------
function Check(parentChk, ChildId) {
var oElements = document.getElementsByTagName("INPUT");
var bIsChecked = parentChk.checked;
for (i = 0; i < oElements.length; i++) {
if (IsCheckBox(oElements[i]) &&
IsMatch(oElements[i].id, ChildId)) {
oElements[i].checked = bIsChecked;
}
}
}
function IsMatch(id, ChildId) {
var sPattern = '^ctl00_ContentPlaceHolder1_GridView1.*' + ChildId + '$';
var sPattern = '^Repeater1_.*' + ChildId + '$';
var oRegExp = new RegExp(sPattern);
if (oRegExp.exec(id))
return true;
else
return false;
}
function IsCheckBox(chk) {
if (chk.type == 'checkbox') return true;
else return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align: center">
<asp:Label ID="L_login_msg" runat="server" ForeColor="Red"></asp:Label><br />
<asp:Panel ID="Panel1" runat="server">
<table width="600" align="center">
<tr>
<td align="center"><font class="title1">檔案(圖片)管理
<asp:Label ID="L_total" runat="server"></asp:Label></font></td>
</tr>
<tr>
<td align="center"><asp:Label ID="L_errmsg" runat="server" /></td>
</tr>
<tr><td class="td_bg_line"></td></tr>
<% if (Convert.ToString(Request["mode"]) !="upload"){%>
<tr>
<td align="center">
<div align="center" class="word5">注意:若為「系統資料夾」或資料夾中尚有資料,則該資料夾無法刪除!</div>
</td>
</tr>
<% }%>
<tr><td class="td_word150" align="left">
<asp:Image ID="Image2" runat="server" ImageUrl="../images/icon09.gif" />
<asp:Label ID="L_path" runat="server"></asp:Label>
</td></tr>
<tr><td class="td_word150" align="center">
<asp:Label ID="msg" runat="server" ForeColor="Red"></asp:Label></td></tr>
<tr runat ="server" id="tr1"><td class="td_bg_line"></td></tr>
</table>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<table width="600" cellpadding="0" cellspacing="0" align="center">
<tr><td align="left">
<div style="width:600px">
<div style="float:left">
<input type="checkbox" id="chkAll" name="chkAll" onClick="Check(this,'CheckBox1')" /><label for="chkAll">全選</label>
<span style="margin-left:20px">排序方式:</span>
<asp:DropDownList ID="sortWay" runat="server" AutoPostBack="true" OnSelectedIndexChanged="sortWay_SelectedIndexChanged">
<asp:ListItem Value="c_date$desc" Text="依日期"></asp:ListItem>
<asp:ListItem Value="filename$asc" Text="依檔名"></asp:ListItem>
</asp:DropDownList>
</div>
<asp:Panel ID="searchPanel" style="float:right" runat="server" DefaultButton="searchBt">
<table border="0">
<tr>
<td>搜尋此目錄的檔案:</td>
<td><asp:TextBox ID="search" runat="server"></asp:TextBox></td>
<td><asp:LinkButton ID="searchBt" runat="server" CausesValidation="false" OnClick="searchBt_Click"><img src="../images/04.gif" border="0" /></asp:LinkButton></td>
</tr>
</table>
</asp:Panel>
</div>
<asp:Repeater id=Repeater1 runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<div class="picdiv">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
<tr><td align="center" valign="middle" class="picdivtd"><%#Eval("review") %></td></tr></table>
<div style="width:120px; height:20px; overflow:hidden; text-align:left">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td width="10" valign="top">
<asp:CheckBox ID="CheckBox1" Visible="false" runat="server" />
</td><td align="left" style="color:blue">
<%#Eval("filename")%>
<asp:ImageButton ID="ImageButton1" runat="server" Visible="false" OnClientClick="return confirm('是否確定刪除此資料夾?\n\n注意若此資料夾中尚有資料時將無法刪除');" CommandArgument='<%#Eval("filename2") + "|" + Eval("filekind")%>' OnClick="ImageButton1_Click" ImageUrl="../images/del.gif" />
</td></tr>
</table>
</div>
<div style="float :right ; text-align:right; color:green">
<%#Eval("filesize") %>
</div>
<asp:HiddenField ID="filekind" runat="server" />
</div>
<asp:Panel ID="splitDiv" style="clear:both" Visible="false" runat="server"></asp:Panel>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<table width="600" align="center">
<tr><td align="center">
<asp:LinkButton ID="LinkButton1" Font-Underline="false" OnClick="LinkButton1_Click" runat="server">上一頁</asp:LinkButton>
&nbsp;|&nbsp;
<asp:LinkButton ID="LinkButton2" Font-Underline="false" OnClick="LinkButton2_Click" runat="server">下一頁</asp:LinkButton>
&nbsp;|&nbsp;
<asp:DropDownList ID="nowpage" AutoPostBack="true" runat="server" OnSelectedIndexChanged="nowpage_SelectedIndexChanged">
</asp:DropDownList>
頁,共
<asp:Label ID="maxpage" runat="server"></asp:Label>
頁,總計
<asp:Label ID="dirTotal" runat="server"></asp:Label>
個資料夾
<asp:Label ID="total" runat="server"></asp:Label>
個檔案
</td></tr>
<tr><td class="td_bg_line"></td></tr>
<tr><td align="center" valign="bottom" height="30">
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="../images/upload.gif" OnClick="ImageButton2_Click" />
<asp:ImageButton ID="dell_all" runat="server" ImageUrl="~/admin/images/del_all.gif" OnClientClick="return confirm('是否確定刪除勾選的檔案?');" OnClick="dell_all_Click" /></td></tr>
<tr><td class="td_bg_line"></td></tr>
</table>
<asp:Panel ID="Panel2" runat="server">
<asp:Panel ID="Panel3" runat="server" Visible="false">
<table align="center" bgcolor="#ffffff" border="1" cellpadding="2" cellspacing="0" width="600">
<tr>
<td class="td4a" colspan="2">
<div align="center">檔案上傳系統</div>
</td>
</tr>
<tr>
<td class="td1a" width="100">
<div align="right">上傳1</div>
</td>
<td class="td2a">
<input id="file1" runat="server" name="file" type="file" size="50" /></td>
</tr>
<tr>
<td class="td1a">
<div align="right">上傳2</div>
</td>
<td class="td2a">
<input id="file2" runat="server" name="file" type="file" size="50" /></td>
</tr>
<tr>
<td class="td1a">
<div align="right">上傳3</div>
</td>
<td class="td2a"><input id="file3" runat="server" name="file" type="file" size="50" /></td>
</tr>
<tr>
<td align="center" class="td4a" colspan="2" height="30"><asp:ImageButton ID="Button1" runat="server" ImageUrl="../images/upload.gif" OnClick="Button1_Click" /></td>
</tr>
</table>
<table width="600" align="center">
<tr><td class="td_bg_line"></td></tr>
</table>
</asp:Panel>
<table align="center" bgcolor="#ffffff" border="1" cellpadding="2" cellspacing="0" width="600">
<tr>
<td class="td4a" colspan="2">
<div align="center">
新增資料夾</div>
</td>
</tr>
<tr>
<td class="td1a" width="100">
<div align="right">
資料夾名稱:</div>
</td>
<td class="td2a">
<asp:TextBox ID="folder_name" runat="server" Width="400px"></asp:TextBox>
<asp:RegularExpressionValidator ValidationGroup="folder_va" ControlToValidate="folder_name" Display="Dynamic" ErrorMessage="<div>只能輸入英文或數字!</div>" ID="RegularExpressionValidator11" runat="server" ValidationExpression="^[A-Za-z0-9]+$" />
</td>
</tr>
<tr>
<td align="center" class="td4a" colspan="2" height="30"><asp:ImageButton ID="creat_folder" ValidationGroup="folder_va" OnClick="creat_folder_Click" runat="server" ImageUrl="~/admin/images/newfolder.gif" /></td>
</tr>
</table>
<table width="600" align="center">
<tr><td class="td_bg_line"></td></tr>
</table>
</asp:Panel>
</asp:View>
<asp:View ID="View2" runat="server">
<script type="text/javascript" src="../../App_Script/swfupload/swfupload.js"></script>
<script type="text/javascript" src="../../App_Script/swfupload/handlers2.js"></script>
<script type="text/javascript">
var swfu;
window.onload = function() {
swfu = new SWFUpload({
// Backend Settings
upload_url: "upload.aspx?dirname=<%=(!string.IsNullOrEmpty(Request["defpath"])?Request["defpath"].ToString() + "/":"") + Convert.ToString(Request["dirname"])%>",
post_params: {
"ASPSESSID": "1"
},
// File Upload Settings
file_size_limit: "4 MB",
file_types: "*.*",
file_types_description: "Files",
file_upload_limit: "0", // Zero means unlimited
// Event Handler Settings - these functions as defined in Handlers.js
// The handlers are not part of SWFUpload but are part of my website and control how
// my website reacts to the SWFUpload events.
file_queue_error_handler: fileQueueError,
file_dialog_complete_handler: fileDialogComplete,
upload_progress_handler: uploadProgress,
upload_error_handler: uploadError,
upload_success_handler: uploadSuccess,
upload_complete_handler: uploadComplete,
// Button settings
button_image_url: "../../App_Script/swfupload/images/XPButtonNoText_160x22.png",
button_placeholder_id: "spanButtonPlaceholder",
button_width: 160,
button_height: 22,
button_text: '<span class="buttonSmall">請選擇要上傳的檔案</span>',
button_text_style: '.button { font-family: Helvetica, Arial, sans-serif; font-size: 14pt;} .buttonSmall { font-size: 12pt; }',
button_text_top_padding: 1,
button_text_left_padding: 5,
// Flash Settings
flash_url: "../../App_Script/swfupload/swfupload.swf", // Relative to this file
custom_settings: {
upload_target: "divFileProgressContainer"
},
// Debug Settings
debug: false
});
}
</script>
<center>
<div id="swfu_container" style="margin: 0px 10px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr><td><span id="spanButtonPlaceholder"></span></td>
<td width="20"></td>
<td><asp:Button ID="Button2" runat="server" Text="返回" OnClick="Button2_Click" /></td></tr>
</table>
<div id="divFileProgressContainer" style="height: 75px;"></div>
<div id="thumbnails"></div>
</div>
<table width="600" align="center">
<tr><td class="td_bg_line"></td></tr>
</table>
</center>
</asp:View>
<asp:View ID="View3" runat="server">
<link href="../../App_Script/jquery-upload-file-master/css/uploadfile.css" rel="stylesheet" />
<script src="../../App_Script/jquery-upload-file-master/js/jquery.uploadfile.js"></script>
<center>
<div id="swfu_container" style="margin: 0px 10px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr><td><div id="fileuploader">請選擇要上傳的檔案</div></td>
<td width="20"></td>
<td valign="top"><asp:Button ID="Button3" runat="server" Text="返回" OnClick="Button2_Click" /></td></tr>
</table>
<div id="divFileProgressContainer" style="height: 75px;"></div>
<div id="thumbnails"></div>
</div>
<table width="600" align="center">
<tr><td class="td_bg_line"></td></tr>
</table>
</center>
<script>
$(document).ready(function()
{
$("#fileuploader").uploadFile({
url:"upload.aspx?dirname=<%=(!string.IsNullOrEmpty(Request["defpath"])?Request["defpath"].ToString() + "/":"") + Convert.ToString(Request["dirname"])%>",
fileName:"Filedata",
uploadFolder:"images",
afterUploadAll:function()
{
$("#divFileProgressContainer").html("<div style='padding-top:10px'>您所選擇的檔案皆已上傳</div>");
}
});
});
</script>
</asp:View>
</asp:MultiView>
<table width="600" align="center">
<tr>
<td height="30" valign="bottom" align="center">
<a href="javascript:window.close()"><asp:Image ID="Image1" runat="server" ImageUrl="~/admin/images/close.gif" /></a></td>
</tr>
</table>
</asp:Panel>
</div>
</form>
</body>
</html>

View File

@@ -0,0 +1,635 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
public partial class admin_filemanager_index : System.Web.UI.Page
{
string db = ConfigurationManager.ConnectionStrings["shopConn"].ConnectionString;
string p_name = ConfigurationManager.ConnectionStrings["shopConn"].ProviderName;
string[] systemDirs = ConfigurationManager.AppSettings["systemDirs"].Split(',');
string scc = ConfigurationManager.AppSettings["shopCarCode"].ToString();
MyWeb.web_config webconfig = new MyWeb.web_config();
protected void Page_Load(object sender, EventArgs e)
{
if (MyWeb.admin.chkAdmIP && (MyWeb.admin.chkTwIP || MyWeb.admin.chkAdmIP_Enable))
{
if (!IsPostBack)
{
if ((Request.Cookies[scc + "_ezFileSort"] != null))
{
sortWay.SelectedValue = Request.Cookies[scc + "_ezFileSort"].Value;
}
saveSort(false);
MyWeb.admin admin = new MyWeb.admin();
if (admin.isLoign())
{
if (admin.info.login_ip != MyWeb.admin.MyIP)
{
Response.Clear();
Response.StatusCode = 404;
Response.End();
}
//定義初始路徑
ViewState["root_path"] = "../../upload/";
if (!string.IsNullOrEmpty(Request["defpath"]))
{
ViewState["root_path"] += Request["defpath"].ToString() + "/";
}
//參數,如有需要增加,請接續後面
ViewState["QueryString"] = "&CKEditorFuncNum=" + Convert.ToString(Request["CKEditorFuncNum"]) + "&rtnobj=" + Convert.ToString(Request["rtnobj"]) + "&CKEditor=" + Convert.ToString(Request["CKEditor"]) + "&langCode=" + Convert.ToString(Request["langCode"]) + "&defpath=" + Convert.ToString(Request["defpath"]);
string http_path = "";
MyWeb.sql sql = new MyWeb.sql();
DataTable dt = sql.selectTable(db, p_name, "SELECT pic_url FROM company");
if (dt.Rows.Count > 0)
{
http_path = dt.Rows[0]["pic_url"].ToString();
}
ViewState["http_path"] = http_path + "/upload/"; //定義上傳圖片實體路徑
if (!string.IsNullOrEmpty(Request["defpath"]))
{
ViewState["http_path"] += Request["defpath"].ToString() + "/";
}
ViewState["total_bytes"] = 0; //定義總檔案大小初始值
if (!webconfig.isStrNull(Request["kw"]))
{
search.Text = Request["kw"];
}
if (Convert.ToString(Request["mode"]) == "upload")
{
HttpBrowserCapabilities hbc = Request.Browser;
//Response.Write(hbc.Browser);
if (hbc.Browser.IndexOf("InternetExplorer") > -1 | hbc.Browser.ToUpper().IndexOf("IE") > -1)
{
MultiView1.ActiveViewIndex = 1;
}
else
{
MultiView1.ActiveViewIndex = 2;
}
L_path.Text = "";
Image2.Visible = false;
tr1.Visible = false;
}
else
{
load_dir_files(); //檔案列表
}
}
else
{
Response.Clear();
Response.StatusCode = 404;
Response.End();
//Panel1.Visible = false;
//L_login_msg.Text = "<br><br><br><br><br><br>您尚未登錄管理!";
}
}
}
else
{
Response.Clear();
Response.StatusCode = 404;
Response.End();
}
}
#region
public void load_dir_files() {
//計算總檔案大小
//total_bytes("");
DataTable dt = new DataTable("Dt1");
//定義DataTable欄位名稱
dt.Columns.Add(new DataColumn("filename"));
dt.Columns.Add(new DataColumn("review"));
dt.Columns.Add(new DataColumn("filesize"));
dt.Columns.Add(new DataColumn("c_date"));
dt.Columns.Add(new DataColumn("filename2"));
dt.Columns.Add(new DataColumn("filekind"));
dt.Columns.Add(new DataColumn("fileqty"));
dt.Columns.Add(new DataColumn("isDir"));
//取得目錄路徑
string dirpath = "";
string dirpath2 = "";
string dirpath3 = "";
string dirpath4 = "";
if (Convert.ToString(Request["dirname"]) != "" & Request["dirname"]!=null)
{
dirpath = "/" + Convert.ToString(Request["dirname"]);
dirpath4 = Convert.ToString(Request["dirname"]) + "/";
string[] v = Convert.ToString(Request["dirname"]).Split('/');
for (int ii = 0; ii < v.Length; ii++) {
if (dirpath2 != "")
{
dirpath2 += "/" + v[ii];
if (ii == v.Length - 1)
{
dirpath3 += "/" + v[ii];
}
else {
dirpath3 += "/<a href='index.aspx?dirname=" + HttpUtility.UrlEncode(dirpath2) + ViewState["QueryString"].ToString() + "'>" + HttpUtility.HtmlEncode(v[ii]) + "</a>";
}
}
else {
dirpath2 += v[ii];
if (ii == v.Length - 1)
{
dirpath3 += v[ii];
}
else {
dirpath3 += "<a href='index.aspx?dirname=" + HttpUtility.UrlEncode(dirpath2) + ViewState["QueryString"].ToString() + "'>" + HttpUtility.HtmlEncode(v[ii]) + "</a>";
}
}
}
L_path.Text = "<a href='index.aspx" + ViewState["QueryString"].ToString().Replace("&CKEditorFuncNum=", "?CKEditorFuncNum=") + "'>根目錄</a>/" + dirpath3;
}
else {
dirpath = "";
dirpath4 = "";
L_path.Text = "";
Image2.Visible = false;
tr1.Visible = false;
}
string kw ="";
if (!webconfig.isStrNull(Request["kw"]))
{
kw = Request["kw"];
}
//定義資料
string path = Server.MapPath(ViewState["root_path"].ToString() + dirpath);
DirectoryInfo dirInfo= new DirectoryInfo(path);
DirectoryInfo[] subDirs = dirInfo.GetDirectories();
FileInfo[] subFiles = dirInfo.GetFiles();
//將資料夾名稱填入DataTable
string child_dirinfo = "";
string new_dir = "";
for (int i = 0; i < subDirs.Length; i++) {
bool chkSearch = true;
if (kw != "")
{
if (subDirs[i].Name.ToLower().IndexOf(kw.ToLower()) == -1)
{
chkSearch = false;
}
}
if (chkSearch)
{
//取得子資料夾資訊
string path2 = Server.MapPath(ViewState["root_path"].ToString() + dirpath + "/" + subDirs[i].Name);
DirectoryInfo dirInfo2 = new DirectoryInfo(path2);
DirectoryInfo[] subDirs2 = dirInfo2.GetDirectories();
FileInfo[] subFiles2 = dirInfo2.GetFiles();
child_dirinfo = "內有 <span class=\"text-primary\">" + subDirs2.Length.ToString() + "</span> 資料夾<br><span class=\"text-primary\">" + subFiles2.Length + "</span> 個檔案";
string fileqty = "";
string filekind = "";
filekind = "A";
fileqty = "B";
bool chkAgin = true;
//upload的目錄下
if (dirpath == "")
{
foreach (string chkDir in systemDirs)
{
if (subDirs[i].Name.ToLower() == chkDir.ToLower())
{
filekind = "C";
fileqty = "B";
chkAgin = false;
break;
}
}
}
if (chkAgin & subDirs2.Length == 0 & subFiles2.Length == 0)
{
filekind = "A";
fileqty = "A";
}
if (Convert.ToString(Request["dirname"]) != "" & Request["dirname"] != null)
{
new_dir = Request["dirname"] + "/" + subDirs[i].Name;
}
else
{
new_dir = subDirs[i].Name;
}
string subfilename = "<span title=\"" + HttpUtility.HtmlEncode(subDirs[i].Name) + "\">" + HttpUtility.HtmlEncode(subDirs[i].Name) + "</span>";
string review_file = "<a href=\"index.aspx?dirname=" + HttpUtility.UrlEncode(new_dir) + ViewState["QueryString"].ToString() + "\" title=\"" + HttpUtility.HtmlEncode(subDirs[i].Name) + "\"><img src=\"images/dir.png\" border=\"0\" width=\"100\" /></a>";
dt.Rows.Add(subfilename, review_file, child_dirinfo, subDirs[i].LastWriteTime.ToString("yyyyMMddHHmmssfff"), subDirs[i].Name, filekind, fileqty, 1);
}
}
dirTotal.Text = subDirs.Length.ToString();
//將檔案名稱填入DataTable
for (int j = 0; j < subFiles.Length; j++)
{
bool chkSearch = true;
if (kw != "")
{
if (subFiles[j].Name.ToLower().IndexOf(kw.ToLower()) == -1)
{
chkSearch = false;
}
}
if (chkSearch)
{
string[] tmp = subFiles[j].Name.Split('.');
string fileSubName = tmp[tmp.Length - 1].ToLower();
string viewPic = "";
if (fileSubName == "jpg" | fileSubName == "jepg" | fileSubName == "gif" | fileSubName == "png")
{
string picDiaplay = dirpath4 + subFiles[j].Name;
if (!string.IsNullOrEmpty(Request["defpath"]))
{
picDiaplay = Request["defpath"].ToString() + "/" + picDiaplay;
}
viewPic = "<img src=\"../../App_Script/display.ashx?file=" + picDiaplay + "&w=120&h=120\" border=\"0\" />";
}
else
{
viewPic = "<img src=\"images/" + picLog(fileSubName) + ".png\" border=\"0\" />";
}
string subfilename = "<span title=\"" + HttpUtility.HtmlEncode(subFiles[j].Name) + "\">" + HttpUtility.HtmlEncode(subFiles[j].Name) + "</span>";
string review_file = "<a href=\"#\" title=\"" + HttpUtility.HtmlEncode(subFiles[j].Name) + "\" onclick=\"OpenFile('" + ViewState["http_path"] + dirpath4 + HttpUtility.UrlEncode(subFiles[j].Name) + "');return false;\">" + viewPic + "</a>";
dt.Rows.Add(subfilename, review_file, (subFiles[j].Length / 1024).ToString("0.00") + " KB", subFiles[j].LastWriteTime.ToString("yyyyMMddHHmmssfff"), subFiles[j].Name, "B", "X", 0);
}
}
total.Text = subFiles.Length.ToString();
dt.DefaultView.Sort = "isDir desc, " + sortWay.SelectedValue.Replace("$", " ");
PagedDataSource objPage = new PagedDataSource();
objPage.DataSource = dt.DefaultView;
objPage.AllowPaging = true;
objPage.PageSize = 12;
int CurPage = 1;
if (Request["page"]!=null)
{
CurPage = Convert.ToInt32(Request["page"]);
}
if (CurPage > objPage.PageCount)
{
CurPage = objPage.PageCount;
}
objPage.CurrentPageIndex = CurPage - 1;
for (int i = 1; i <= objPage.PageCount; i++) {
nowpage.Items.Add(i.ToString());
}
if (nowpage.Items.Count > 0) {
nowpage.SelectedValue = CurPage.ToString(); //顯示目前第幾頁
}
maxpage.Text = objPage.PageCount.ToString(); //顯示最大頁數
Repeater1.DataSource = objPage;
Repeater1.DataBind();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataRowView data = (DataRowView)e.Item.DataItem;
if (e.Item.ItemIndex % 4 == 3) {
Panel splitDiv = (Panel)e.Item.FindControl("splitDiv");
splitDiv.Visible = true;
}
CheckBox CheckBox1 = (CheckBox)e.Item.FindControl("CheckBox1");
if (data["filekind"].ToString() == "B" | (data["filekind"].ToString() == "A" & data["fileqty"].ToString() == "A"))
{
CheckBox1.Visible = true;
}
HiddenField filekind = (HiddenField)e.Item.FindControl("filekind");
filekind.Value = data["filekind"].ToString();
}
public string picLog(string subName){
string rtn = "|ai|asp|aspx|js|jsp|pdf|php|psd|swf|txt|";
if (rtn.IndexOf("|" + subName + "|", 0) > -1)
{
return subName;
}
else if (subName == "xls" | subName == "xlsx")
{
return "excel";
}
else if (subName == "doc" | subName == "docx")
{
return "word";
}
else if (subName == "zip" | subName == "rar")
{
return "zip";
}
else if (subName == "htm" | subName == "html")
{
return "html";
}
else if (subName == "ppt" | subName == "pps" | subName == "pptx" | subName == "ppsx")
{
return "powerpoint";
}
else if (subName == "bmp" | subName == "tif")
{
return "photo";
}
else if (subName == "wmv" | subName == "mp4" | subName == "rm" | subName == "mov")
{
return "video";
}
else
{
return "unknown";
}
}
protected void nowpage_SelectedIndexChanged(object sender, EventArgs e)
{
GoToPage(Convert.ToInt32(nowpage.SelectedValue));
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
int pg = Convert.ToInt32(nowpage.SelectedValue);
GoToPage((pg - 1 > 0 ? pg - 1 : 1));
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
int pg = Convert.ToInt32(nowpage.SelectedValue);
int maxpg = Convert.ToInt32(maxpage.Text);
GoToPage((pg + 1 <= maxpg ? pg + 1 : maxpg));
}
public void GoToPage(int p) {
MyWeb.web_config web_config = new MyWeb.web_config();
string url = web_config.rtnQueryString("page");
Response.Redirect(url + "&page=" + p.ToString());
}
//計算目前總檔案大小
public void total_bytes(string dirpath)
{
string path = Server.MapPath(ViewState["root_path"].ToString() + dirpath);
DirectoryInfo dirInfo = new DirectoryInfo(path);
DirectoryInfo[] subDirs = dirInfo.GetDirectories();
FileInfo[] subFiles = dirInfo.GetFiles();
long all_bytes = Convert.ToInt64(ViewState["total_bytes"]);
for (int j = 0; j < subFiles.Length; j++)
{
all_bytes += subFiles[j].Length;
}
//Response.Write("路徑=" + dirpath + "<br>");
//Response.Write("個別資料夾總和=" + (all_bytes / 1024).ToString("0.00") + "<br><br><br>");
ViewState["total_bytes"] = all_bytes;
for (int j = 0; j < subDirs.Length; j++)
{
total_bytes(dirpath + "/" + subDirs[j].Name);
}
}
#endregion
#region
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string[] v = ((ImageButton)sender).CommandArgument.Split('|');
if (v[1] == "A") {
string path = Server.MapPath(Convert.ToString(ViewState["root_path"]) + Convert.ToString(Request["dirname"]) + "/" + v[0]);
DirectoryInfo DirectoryInfo = new DirectoryInfo(path);
if (DirectoryInfo.Exists)
{
try
{
DirectoryInfo.Delete();
Response.Redirect("index.aspx?dirname=" + Convert.ToString(Request["dirname"]) + ViewState["QueryString"].ToString());
}
catch (Exception)
{
msg.Text = "(刪除失敗,因為要刪除資料夾不是空的!)";
}
}
else {
msg.Text = "(要刪除的資料夾:<font color=blue>" + v[0] + "</font> 不存在!!)";
}
}
}
protected void dell_all_Click(object sender, ImageClickEventArgs e)
{
CheckBox cbox;
ImageButton img;
foreach (RepeaterItem item in Repeater1.Items)
{
cbox = (CheckBox)item.FindControl("CheckBox1");
img = (ImageButton)item.FindControl("ImageButton1");
string[] v = img.CommandArgument.Split('|');
if (cbox.Checked) {
string path = Server.MapPath(Convert.ToString(ViewState["root_path"]) + Convert.ToString(Request["dirname"]) + "/" + v[0]);
HiddenField filekind = (HiddenField)item.FindControl("filekind");
if (filekind.Value == "A")
{
DirectoryInfo DirectoryInfo = new DirectoryInfo(path);
if (DirectoryInfo.Exists)
{
try
{
DirectoryInfo.Delete();
}
catch (Exception)
{
msg.Text = "(刪除失敗,因為要刪除資料夾不是空的!)";
}
}
else {
msg.Text = "(要刪除的資料夾:<font color=blue>" + v[0] + "</font> 不存在!!)";
}
}
else
{
FileInfo FileInfo = new FileInfo(path);
if (FileInfo.Exists)
{
FileInfo.Delete();
}
else {
msg.Text = "(要刪除的檔案:<font color=blue>" + v[0] + "</font> 不存在!!)";
}
}
}
}
GoToPage(Convert.ToInt32(nowpage.SelectedValue));
}
#endregion
#region
protected void creat_folder_Click(object sender, ImageClickEventArgs e)
{
string path = Server.MapPath(Convert.ToString(ViewState["root_path"]) + Convert.ToString(Request["dirname"]) + "/" + folder_name.Text);
DirectoryInfo DirectoryInfo = new DirectoryInfo(path);
if (DirectoryInfo.Exists)
{
msg.Text = "(資料夾名稱已存在,無法重覆新增!)";
}
else
{
DirectoryInfo.Create();
Response.Redirect("index.aspx?dirname=" + Convert.ToString(Request["dirname"]) + ViewState["QueryString"].ToString());
}
}
#endregion
#region
protected void Button1_Click(object sender, ImageClickEventArgs e)
{
string up_path = Server.MapPath( Convert.ToString(ViewState["root_path"]) + Convert.ToString(Request["dirname"]));
HttpFileCollection objFileCollection = Request.Files;
HttpPostedFile file;
int counter = 0;
for (int i = 0; i < objFileCollection.Count; i++) {
file = objFileCollection[i];
if (file.ContentLength != null) {
file.SaveAs(up_path + "/" + Path.GetFileName(file.FileName));
counter++;
}
}
if (counter == 0)
{
msg.Text = "(請選擇要上傳的檔案!)";
}
else
{
msg.Text = "(上傳【" + counter.ToString() + "】個檔案成功!)";
Response.Redirect("index.aspx?dirname=" + Convert.ToString(Request["dirname"]) + ViewState["QueryString"].ToString());
}
}
#endregion
#region
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
string url = Request.Url.AbsoluteUri;
if (url.IndexOf(".aspx?", 0) > -1)
{
url += "&mode=upload";
}
else {
url += "?mode=upload";
}
Response.Redirect(url);
}
protected void Button2_Click(object sender, EventArgs e)
{
string url = Request.Url.AbsoluteUri;
url = url.Replace("&mode=upload", "");
url = url.Replace("?mode=upload", "");
string[] v = url.Split('?');
if (v.Length == 0) {
url = url.Replace("&CKEditorFuncNum=", "?CKEditorFuncNum=");
}
Response.Redirect(url);
}
#endregion
#region
protected void sortWay_SelectedIndexChanged(object sender, EventArgs e)
{
saveSort(true);
}
protected void saveSort(bool refresh)
{
Response.Cookies[scc + "_ezFileSort"].Value = sortWay.SelectedValue;
Response.Cookies[scc + "_ezFileSort"].Expires = DateTime.Now.AddYears(1);
if (refresh) {
Response.Redirect(Request.Url.AbsoluteUri);
}
}
#endregion
#region
protected void searchBt_Click(object sender, EventArgs e)
{
search.Text = search.Text.Trim();
string kwStr = "";
if (search.Text != "")
{
kwStr = "&kw=" + Server.UrlEncode(search.Text);
}
string[] q = { "kw", "page" };
Response.Redirect(Request.Url.AbsolutePath + webconfig.rtnQueryString(q) + kwStr);
}
#endregion
}

View File

@@ -0,0 +1,16 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="upload.aspx.cs" Inherits="admin_filemanager_upload" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>SWFUpload Revision v2.0 Application Demo (ASP.Net 2.0)</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Upload Page</p>
</div>
</form>
</body>
</html>

View File

@@ -0,0 +1,223 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
public partial class admin_filemanager_upload : System.Web.UI.Page
{
//限制寬度尺寸不得超過1024
const double maxSize = 1024;
string scc = ConfigurationManager.AppSettings["shopCarCode"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
MyWeb.admin admin = new MyWeb.admin();
if (MyWeb.admin.chkAdmIP && (MyWeb.admin.chkTwIP || MyWeb.admin.chkAdmIP_Enable) && admin.isLoign())
{
if (admin.info.login_ip != MyWeb.admin.MyIP)
{
Response.Clear();
Response.StatusCode = 404;
Response.End();
}
try
{
MyWeb.fileSystem fileSystem = new MyWeb.fileSystem();
HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];
string up_path = Server.MapPath("~/upload/" + Convert.ToString(Request["dirname"]).Replace("../", ""));
DirectoryInfo dir = new DirectoryInfo(up_path);
if (!dir.Exists) { dir.Create(); }
string savePath = up_path + (up_path.Substring(up_path.Length - 1, 1) != "/" ? "/" : "") + jpeg_image_upload.FileName.Replace(" ", "_");
int re = 0;
while (true)
{
FileInfo fInfo = new FileInfo(savePath);
if (fInfo.Exists)
{
string fname = jpeg_image_upload.FileName.Replace(" ", "_");
re++;
string[] f = fname.Split('.');
fname = f[0] + "(" + re.ToString() + ")" + (f.Length > 1 ? "." + f[1] : "");
savePath = up_path + (up_path.Substring(up_path.Length - 1, 1) != "/" ? "/" : "") + fname;
}
else { break; }
}
if (fileSystem.isPhoto(jpeg_image_upload.FileName))
{
string[] n = jpeg_image_upload.FileName.Split('.');
System.Drawing.Image Bm = new System.Drawing.Bitmap(jpeg_image_upload.InputStream);
foreach (PropertyItem pi in Bm.PropertyItems)
{
// orientation tag id is 274
if (pi.Id == 274)
{
switch (pi.Value[0])
{
case 2:
Bm.RotateFlip(RotateFlipType.RotateNoneFlipX);
break;
case 3:
Bm.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case 4:
Bm.RotateFlip(RotateFlipType.RotateNoneFlipY);
break;
case 5:
Bm.RotateFlip(RotateFlipType.Rotate90FlipX);
break;
case 6:
Bm.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
case 7:
Bm.RotateFlip(RotateFlipType.Rotate270FlipX);
break;
case 8:
Bm.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
default:
break;
}
}
}
double newWidth = Bm.Width;
double newHeight = Bm.Height;
if (Bm.Width > maxSize)
{
newWidth = maxSize;
newHeight = maxSize / Bm.Width;
newHeight = newHeight * Bm.Height;
}
/*if (Bm.Width > Bm.Height)
{
if (Bm.Width > maxSize)
{
newWidth = maxSize;
newHeight = maxSize / Bm.Width;
newHeight = newHeight * Bm.Height;
}
}
else
{
if (Bm.Height > maxSize)
{
newHeight = maxSize;
newWidth = maxSize / Bm.Height;
newWidth = newWidth * Bm.Width;
}
}*/
if (newWidth > 0 & newHeight > 0)
{
string picType = n[n.Length - 1].ToLower();
if (picType == "jpg") { picType = "jpeg"; }
System.Drawing.Image New_Image = new Bitmap((int)newWidth, (int)newHeight);
Graphics ObjGraphics = Graphics.FromImage(New_Image);
MyWeb.global global = new MyWeb.global();
ObjGraphics.InterpolationMode = global.InterpolationMode;
ObjGraphics.SmoothingMode = global.SmoothingMode;
ObjGraphics.CompositingQuality = global.CompositingQuality;
if (picType == "png")
{
ObjGraphics.Clear(Color.Transparent); //清空Graphics, 以透明色填充
}
else
{
ObjGraphics.Clear(Color.White); //清空Graphics, 以白色填充
}
//在指定位置按指定大小繪制原圖片的片段
ObjGraphics.DrawImage(Bm, new Rectangle(0, 0, (int)newWidth, (int)newHeight), new Rectangle(0, 0, Bm.Width, Bm.Height), GraphicsUnit.Pixel);
if (fileSystem.WatermarkMode == "2")
{
string FileNameAndPath = HttpContext.Current.Server.MapPath(fileSystem.WatermarkPath);
System.Drawing.Image Watermark_Image = System.Drawing.Image.FromFile(FileNameAndPath);
int w_Width = Convert.ToInt32(Math.Round(Convert.ToDouble(newWidth) * 0.8));
int w_Height = Convert.ToInt32(Watermark_Image.Height * (Convert.ToDouble(w_Width) / Convert.ToDouble(Watermark_Image.Width)));
int w_myX = ((int)newWidth - w_Width) / 2; //浮水印水平置中
int w_myY = ((int)newHeight - w_Height) / 2 + w_Height; //浮水印水平垂直置中向下偏移一個高度
var colorMatrix = new ColorMatrix();
colorMatrix.Matrix33 = (float)Convert.ToSingle(fileSystem.WatermarkPct);
var imageAttributes = new ImageAttributes();
imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
ObjGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
ObjGraphics.DrawImage(
Watermark_Image,
new Rectangle(w_myX, w_myY, w_Width, w_Height),
0,
0,
Watermark_Image.Width,
Watermark_Image.Height,
GraphicsUnit.Pixel,
imageAttributes);
}
//下方設定使JPG質量
EncoderParameters EPS = new EncoderParameters();
EncoderParameter EP = new EncoderParameter(Encoder.Quality, global.ImageCompressionQuality);
EPS.Param[0] = EP;
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ICI = null;
foreach (ImageCodecInfo codec in codecs)
{
if (codec.MimeType == "image/" + picType)
{
ICI = codec;
break;
}
}
New_Image.Save(savePath, ICI, EPS);
New_Image.Dispose();
ObjGraphics.Dispose();
}
else
{
jpeg_image_upload.SaveAs(savePath);
}
Bm.Dispose();
}
else if (fileSystem.isAllowed(jpeg_image_upload.FileName))
{
jpeg_image_upload.SaveAs(savePath);
}
}
catch (Exception)
{
// If any kind of error occurs return a 500 Internal Server error
Response.StatusCode = 500;
Response.Write("An error occured");
Response.End();
}
finally
{
Response.End();
}
}
else
{
Response.Clear();
Response.StatusCode = 404;
Response.End();
}
}
}