From cf06951d9a4b18a9cfa20653b0e21e57c070a3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A5=8A=E6=98=8E=E5=8B=B3=20Ming?= Date: Sun, 6 Mar 2016 03:03:17 +0800 Subject: [PATCH 1/3] fix when add file has error but show success message --- scripts/filemanager.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/filemanager.js b/scripts/filemanager.js index b1d5e51b..fa627150 100644 --- a/scripts/filemanager.js +++ b/scripts/filemanager.js @@ -1795,6 +1795,9 @@ $(function(){ buttons: btns }); + //count newfile success count. + var addfileSuccessCount = 0; + $("div#multiple-uploads").dropzone({ paramName: "newfile", url: fileConnector + '?config=' + userconfig, @@ -1825,6 +1828,9 @@ $(function(){ sending: function(file, xhr, formData) { formData.append("mode", "add"); formData.append("currentpath", path); + + //when send reset count + addfileSuccessCount = 0; }, success: function(file, response) { $('#uploadresponse').empty().html(response); @@ -1832,6 +1838,12 @@ $(function(){ if (data['Code'] == 0) { this.removeFile(file); + + //when success if upload 1+N files , just show onces message + addfileSuccessCount = addfileSuccessCount + 1; + if (config.options.showConfirmation && addfileSuccessCount == 1) { + $.prompt(lg.successful_added_file); + } } else { // this.removeAllFiles(); getFolderInfo(path); @@ -1850,9 +1862,6 @@ $(function(){ getFolderInfo(path); if(path == fileRoot) createFileTree(); $('#filetree').find('a[data-path="' + path + '"]').click().click(); - if(config.options.showConfirmation) { - $.prompt(lg.successful_added_file); - } } } }); From 7238c54dbc4e509b4a19032d97880985a81d649b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A5=8A=E6=98=8E=E5=8B=B3=20Ming?= Date: Sun, 6 Mar 2016 03:05:06 +0800 Subject: [PATCH 2/3] update chinest traditional languages --- scripts/languages/zh-tw.js | 176 ++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/scripts/languages/zh-tw.js b/scripts/languages/zh-tw.js index 737d5363..111e7363 100644 --- a/scripts/languages/zh-tw.js +++ b/scripts/languages/zh-tw.js @@ -1,91 +1,91 @@ { - "ALLOWED_FILE_TYPE": "Only following files are allowed : ", - "AUTHORIZATION_REQUIRED": "您沒有權限使用檔案管理員。", - "DIRECTORY_ALREADY_EXISTS": "目錄 '%s' 已經存在。", - "DIRECTORY_NOT_EXIST": "目錄 %s 不存在。", - "DISALLOWED_FILE_TYPE": "Following files are not allowed : ", - "ERROR_CREATING_ZIP": "Error creating Zip archive", - "ERROR_OPENING_FILE": "Error opening file.", - "ERROR_RENAMING_DIRECTORY": "將目錄 %s 更名到 %s 時發生錯誤。", - "ERROR_RENAMING_FILE": "將檔案 %s 更名到 %s 時發生錯誤。", - "ERROR_REPLACING_FILE": "Please, provide a file having the following extension :", - "ERROR_SAVING_FILE": "Error saving file.", - "ERROR_UPLOADING_FILE": "Error uploading file.", - "ERROR_WRITING_PERM": "You don't have write permissions on that file.", - "FILE_ALREADY_EXISTS": "檔案 '%s' 已經存在。", - "FILE_DOES_NOT_EXIST": "檔案 %s 不存在。", - "INVALID_ACTION": "無效的動作。", - "INVALID_DIRECTORY_OR_FILE": "無效的檔案或目錄。", - "INVALID_FILE_TYPE": "File type is not allowed.", - "INVALID_FILE_UPLOAD": "無效的上傳。", - "INVALID_VAR": "無效的變數 %s。", - "LANGUAGE_FILE_NOT_FOUND": "語系檔不存在。", - "MODE_ERROR": "模式錯誤。", - "NOT_ALLOWED": "You are not allowed to process this action", - "NOT_ALLOWED_SYSTEM": "System permissions do not allow you to perform this action", - "UNABLE_TO_CREATE_DIRECTORY": "無法建立目錄 %s。", - "UNABLE_TO_OPEN_DIRECTORY": "無法開啟目錄 %s。", - "UPLOAD_FILES_SMALLER_THAN": "請上傳小於 %s 的檔案。", - "UPLOAD_IMAGES_ONLY": "請上傳圖檔,不支援圖檔以外的格式。", - "UPLOAD_IMAGES_TYPE_JPEG_GIF_PNG": "圖檔格式僅限於 JPEG, GIF or PNG。", - "browse": "Browse...", - "bytes": " bytes", - "cancel": "取消", - "close": "Close", - "confirmation_delete": "確定刪除檔案?", - "copied": "URL copied !", - "copy_to_clipboard": "Copy to Clipboard", - "could_not_retrieve_folder": "無法取得目錄內容", - "create_folder": "建立目錄", - "created": "建立", - "current_folder": "目前目錄:", - "default_foldername": "我的文件", - "del": "刪除", - "dimensions": "尺寸", - "download": "下載", - "dz_dictDefaultMessage": "Drop files here to upload", - "dz_dictFallbackMessage": "Your browser does not support drag'n'drop file uploads.", - "dz_dictInvalidFileType": "You can't upload files of this type.", - "dz_dictMaxFilesExceeded": "Only %s simultaneous uploads are allowed.", - "edit": "Edit file", - "fck_select_integration": "此功能僅能與 FCKEditor 整合使用。", - "file_size_limit": "The file size limit is : ", - "file_too_big": "The file is too big.", - "gb": "gb", - "grid_view": "切換框格檢視。", - "help_move": "The use of '../' is forbidden. You can access root folder by using '/'.", - "items": "items", - "kb": "kb", - "list_view": "切換清單檢視。", - "loading_data": "傳送檔案...", - "mb": "mb", - "modified": "修改", - "move": "Move to ...", - "name": "名稱", - "new_filename": "輸入新檔案的名稱", - "new_folder": "新目錄", - "no": "否", - "no_foldername": "未提供目錄名稱。", - "parentfolder": "上層目錄", - "prompt_foldername": "輸入新目錄的名稱。", - "quit_editor": "Quit editor", - "rename": "更名", - "replace": "Replace file", - "save": "Save", - "search": "Search", - "search_reset": "Reset", - "select": "選取", - "select_from_left": "從左邊選擇一個項目。", - "size": "大小", - "successful_added_file": "檔案建立成功。", - "successful_added_folder": "目錄建立成功。", - "successful_delete": "刪除成功。", - "successful_edit": "Content update successful.", - "successful_moved": "Move successful.", - "successful_rename": "更名成功", - "successful_replace": "File replacement successful.", - "support_fm": "Filemanager is a free software, please support !", - "upload": "上傳", - "version": "version", + "ALLOWED_FILE_TYPE": "只允許下列附檔名上傳 : ", + "AUTHORIZATION_REQUIRED": "您沒有權限使用檔案管理員。", + "DIRECTORY_ALREADY_EXISTS": "目錄 '%s' 已經存在。", + "DIRECTORY_NOT_EXIST": "目錄 %s 不存在。", + "DISALLOWED_FILE_TYPE": "下列附檔名為不允許清單 : ", + "ERROR_CREATING_ZIP": "Zip檔解壓縮失敗", + "ERROR_OPENING_FILE": "檔案開啟失敗", + "ERROR_RENAMING_DIRECTORY": "將目錄 %s 更名到 %s 時發生錯誤。", + "ERROR_RENAMING_FILE": "將檔案 %s 更名到 %s 時發生錯誤。", + "ERROR_REPLACING_FILE": "請上傳以下附檔名的檔案 :", + "ERROR_SAVING_FILE": "檔案儲存失敗", + "ERROR_UPLOADING_FILE": "檔案上傳失敗", + "ERROR_WRITING_PERM": "您沒有上傳檔案的權限", + "FILE_ALREADY_EXISTS": "檔案 '%s' 已經存在。", + "FILE_DOES_NOT_EXIST": "檔案 %s 不存在。", + "INVALID_ACTION": "無效的動作。", + "INVALID_DIRECTORY_OR_FILE": "無效的檔案或目錄。", + "INVALID_FILE_TYPE": "不允許上傳的附檔名", + "INVALID_FILE_UPLOAD": "無效的上傳。", + "INVALID_VAR": "無效的變數 %s。", + "LANGUAGE_FILE_NOT_FOUND": "語系檔不存在。", + "MODE_ERROR": "模式錯誤。", + "NOT_ALLOWED": "您沒有上傳檔案的權限", + "NOT_ALLOWED_SYSTEM": "您沒有上傳檔案的權限", + "UNABLE_TO_CREATE_DIRECTORY": "無法建立目錄 %s。", + "UNABLE_TO_OPEN_DIRECTORY": "無法開啟目錄 %s。", + "UPLOAD_FILES_SMALLER_THAN": "請上傳小於 %s 的檔案。", + "UPLOAD_IMAGES_ONLY": "請上傳圖檔,不支援圖檔以外的格式。", + "UPLOAD_IMAGES_TYPE_JPEG_GIF_PNG": "圖檔格式僅限於 JPEG, GIF or PNG。", + "browse": "瀏覽...", + "bytes": " bytes", + "cancel": "取消", + "close": "關閉", + "confirmation_delete": "確定刪除檔案?", + "copied": "已複製網址 !", + "copy_to_clipboard": "複製到剪貼簿", + "could_not_retrieve_folder": "無法取得目錄內容", + "create_folder": "建立目錄", + "created": "建立", + "current_folder": "目前目錄:", + "default_foldername": "MyFolder", + "del": "刪除", + "dimensions": "尺寸", + "download": "下載", + "dz_dictDefaultMessage": "拖拉檔案至此上傳", + "dz_dictFallbackMessage": "您的瀏覽器不支援拖拉式檔案上傳", + "dz_dictInvalidFileType": "不允許上傳的附檔名.", + "dz_dictMaxFilesExceeded": "一次僅允許 %s 個檔案上傳.", + "edit": "編輯檔案", + "fck_select_integration": "此功能僅能與 FCKEditor 整合使用。", + "file_size_limit": "檔案上傳大小上限 : ", + "file_too_big": "檔案已超出最大限制", + "gb": "gb", + "grid_view": "切換框格檢視。", + "help_move": "The use of '../' is forbidden. You can access root folder by using '/'.", + "items": "items", + "kb": "kb", + "list_view": "切換清單檢視。", + "loading_data": "傳送檔案...", + "mb": "mb", + "modified": "修改", + "move": "Move to ...", + "name": "名稱", + "new_filename": "輸入新檔案的名稱", + "new_folder": "新目錄", + "no": "否", + "no_foldername": "未提供目錄名稱。", + "parentfolder": "上層目錄", + "prompt_foldername": "輸入新目錄的名稱。", + "quit_editor": "離開編輯模式", + "rename": "更名", + "replace": "重新上傳檔案", + "save": "檔案儲存", + "search": "Search", + "search_reset": "Reset", + "select": "選取", + "select_from_left": "從左邊選擇一個項目。", + "size": "大小", + "successful_added_file": "檔案建立成功。", + "successful_added_folder": "目錄建立成功。", + "successful_delete": "刪除成功。", + "successful_edit": "檔案修改成功", + "successful_moved": "檔案搬移成功", + "successful_rename": "檔案更名成功", + "successful_replace": "檔案重新上傳成功", + "support_fm": "Filemanager is a free software, please support !", + "upload": "上傳", + "version": "version", "yes": "是" } \ No newline at end of file From 22de9d325833ffae4794f29ba3e3d17fda9a1156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A5=8A=E6=98=8E=E5=8B=B3=20Ming?= Date: Sun, 6 Mar 2016 03:13:24 +0800 Subject: [PATCH 3/3] Add two field. check if onlyallowimage & CheckFile --- connectors/mvc/FilemanagerController.cs | 240 ++++++++++++------------ 1 file changed, 125 insertions(+), 115 deletions(-) diff --git a/connectors/mvc/FilemanagerController.cs b/connectors/mvc/FilemanagerController.cs index fe18e824..2f5bb0b0 100644 --- a/connectors/mvc/FilemanagerController.cs +++ b/connectors/mvc/FilemanagerController.cs @@ -1,38 +1,47 @@ // Filemanager ASP.NET MVC connector -// Author: David Hammond -// Based on ASHX connection by Ondřej "Yumi Yoshimido" Brožek | +// Author: David Hammond Based on ASHX connection by Ondřej "Yumi Yoshimido" +// Brožek | using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Configuration; -using System.Web.Script.Serialization; using System.Web.Mvc; +using System.Web.Script.Serialization; namespace MyProject.Areas.FilemanagerArea.Controllers { /// - /// Filemanager controller + /// Filemanager controller /// public class FilemanagerController : Controller { /// - /// Root directory for all file uploads [string] - /// Set in web.config. E.g. + /// 上傳檔案路徑 Root directory for all file uploads [string] Set in web.config. E.g. /// private string RootPath = WebConfigurationManager.AppSettings["Filemanager_RootPath"]; // Root directory for all file uploads [string] /// - /// Directory for icons. [string] - /// Set in web.config E.g. + /// icon的檔案路徑 Directory for icons. [string] Set in web.config E.g. /// private string IconDirectory = WebConfigurationManager.AppSettings["Filemanager_IconDirectory"]; // Icon directory for filemanager. [string] + /// + /// Is only allow imgextensions + /// + private bool IsOnlyImage = Convert.ToBoolean(WebConfigurationManager.AppSettings["Filemanager_IsOnlyImage"]); + + /// + /// File Size Limit by MB , if 0 = unlimit。 + /// + private int LimitFileSizeMB = Convert.ToInt32(WebConfigurationManager.AppSettings["Filemanager_LimitFileSizeMB"]); + /// /// White list of allowed file extensions /// @@ -44,17 +53,17 @@ public class FilemanagerController : Controller private List imgExtensions = new List { ".jpg", ".png", ".jpeg", ".gif", ".bmp" }; // Only allow this image extensions. [string] /// - /// Serializer for generating json responses + /// Serializer for generating json responses /// private JavaScriptSerializer json = new JavaScriptSerializer(); /// - /// Process file manager action + /// Process file manager action /// - /// - /// + /// + /// /// - [Authorize()] + [Authorize] public ActionResult Index(string mode, string path = null) { Response.ClearHeaders(); @@ -67,20 +76,27 @@ public ActionResult Index(string mode, string path = null) { case "getinfo": return Content(GetInfo(path), "application/json", Encoding.UTF8); + case "getfolder": return Content(GetFolderInfo(path), "application/json", Encoding.UTF8); + case "move": var oldPath = Request.QueryString["old"]; var newPath = string.Format("{0}{1}/{2}", Request.QueryString["root"], Request.QueryString["new"], Path.GetFileName(oldPath)); return Content(Move(oldPath, newPath), "application/json", Encoding.UTF8); + case "rename": return Content(Rename(Request.QueryString["old"], Request.QueryString["new"]), "application/json", Encoding.UTF8); + case "replace": return Content(Replace(Request.Form["newfilepath"]), "text/html", Encoding.UTF8); + case "delete": return Content(Delete(path), "application/json", Encoding.UTF8); + case "addfolder": return Content(AddFolder(path, Request.QueryString["name"]), "application/json", Encoding.UTF8); + case "download": if (System.IO.File.Exists(Server.MapPath(path)) && IsInRootPath(path)) { @@ -95,9 +111,11 @@ public ActionResult Index(string mode, string path = null) } case "add": return Content(AddFile(Request.Form["currentpath"]), "text/html", Encoding.UTF8); + case "preview": var fi2 = new FileInfo(Server.MapPath(Request.QueryString["path"])); return new FilePathResult(fi2.FullName, "image/" + fi2.Extension.TrimStart('.')); + default: return Content(""); } @@ -110,10 +128,10 @@ public ActionResult Index(string mode, string path = null) //=================================================================== //========================== END EDIT =============================== - //=================================================================== + //=================================================================== /// - /// Is the file an image file + /// Is the file an image file /// /// /// @@ -123,7 +141,7 @@ private bool IsImage(FileInfo fileInfo) } /// - /// Is the file in the root path? Don't allow uploads outside the root path. + /// Is the file in the root path? Don't allow uploads outside the root path. /// /// /// @@ -133,62 +151,47 @@ private bool IsInRootPath(string path) } /// - /// Add a file + /// Add a file /// /// /// private string AddFile(string path) { - string response; + var errorFormat = ""; + HttpPostedFileBase file = Request.Files.Count == 0 ? null : Request.Files[0]; + + string response = CheckFile(path, file); + + if (!string.IsNullOrWhiteSpace(response)) + return string.Format(errorFormat, response); - if (Request.Files.Count == 0 || Request.Files[0].ContentLength == 0) + //Only allow certain characters in file names + var baseFileName = Regex.Replace(Path.GetFileNameWithoutExtension(file.FileName), @"[^\w_-]", ""); + var filePath = Path.Combine(path, baseFileName + Path.GetExtension(file.FileName)); + + //Make file name unique + var i = 0; + while (System.IO.File.Exists(Server.MapPath(filePath))) { - response = Error("No file provided."); + i = i + 1; + baseFileName = Regex.Replace(baseFileName, @"_[\d]+$", ""); + filePath = Path.Combine(path, baseFileName + "_" + i + Path.GetExtension(file.FileName)); } - else - { - if (!IsInRootPath(path)) - { - response = Error("Attempt to add file outside root path"); - } - else - { - System.Web.HttpPostedFileBase file = Request.Files[0]; - if (!allowedExtensions.Contains(Path.GetExtension(file.FileName).ToLower())) - { - response = Error("Uploaded file type is not allowed."); - } - else - { - //Only allow certain characters in file names - var baseFileName = Regex.Replace(Path.GetFileNameWithoutExtension(file.FileName), @"[^\w_-]", ""); - var filePath = Path.Combine(path, baseFileName + Path.GetExtension(file.FileName)); + file.SaveAs(Server.MapPath(filePath)); - //Make file name unique - var i = 0; - while (System.IO.File.Exists(Server.MapPath(filePath))) - { - i = i + 1; - baseFileName = Regex.Replace(baseFileName, @"_[\d]+$", ""); - filePath = Path.Combine(path, baseFileName + "_" + i + Path.GetExtension(file.FileName)); - } - file.SaveAs(Server.MapPath(filePath)); + response = json.Serialize(new + { + Path = path, + Name = Path.GetFileName(file.FileName), + Error = "No error", + Code = 0 + }); - response = json.Serialize(new - { - Path = path, - Name = Path.GetFileName(file.FileName), - Error = "No error", - Code = 0 - }); - } - } - } - return ""; + return string.Format(errorFormat, response); } /// - /// Add a folder + /// Add a folder /// /// /// @@ -214,7 +217,7 @@ private string AddFolder(string path, string newFolder) } /// - /// Delete a file + /// Delete a file /// /// /// @@ -252,7 +255,7 @@ private string Delete(string path) } /// - /// Generate json for error message + /// Generate json for error message /// /// /// @@ -266,7 +269,7 @@ private string Error(string msg) } /// - /// Get folder information + /// Get folder information /// /// /// @@ -348,17 +351,11 @@ private string GetFolderInfo(string path) if (IsImage(fileInfo)) { - try - { - using (System.Drawing.Image img = System.Drawing.Image.FromFile(fileInfo.FullName)) - { - sb.AppendLine("\"Height\": " + img.Height.ToString() + ","); - sb.AppendLine("\"Width\": " + img.Width.ToString() + ","); - } - } - catch - { - } + using (System.Drawing.Image img = System.Drawing.Image.FromFile(fileInfo.FullName)) + { + sb.AppendLine("\"Height\": " + img.Height.ToString() + ","); + sb.AppendLine("\"Width\": " + img.Width.ToString() + ","); + } } sb.AppendLine("\"Size\": " + fileInfo.Length.ToString() + " "); @@ -377,7 +374,7 @@ private string GetFolderInfo(string path) } /// - /// Get file information + /// Get file information /// /// /// @@ -455,10 +452,8 @@ private string GetInfo(string path) } return sb.ToString(); - } - private string Move(string oldPath, string newPath) { if (!IsInRootPath(oldPath)) @@ -519,7 +514,7 @@ private string Move(string oldPath, string newPath) } /// - /// Rename a file or directory + /// Rename a file or directory /// /// /// @@ -576,49 +571,64 @@ private string Rename(string path, string newName) } /// - /// Replace a file + /// Replace a file /// /// /// private string Replace(string path) { - if (Request.Files.Count == 0 || Request.Files[0].ContentLength == 0) - { - return Error("No file provided."); - } - else if (!IsInRootPath(path)) - { - return Error("Attempt to replace file outside root path"); - } - else + HttpPostedFileBase file = Request.Files.Count == 0 ? null : Request.Files[0]; + + string response = CheckFile(path, file); + + if (!string.IsNullOrWhiteSpace(response)) + return response; + + var fi = new FileInfo(Server.MapPath(path)); + + if (!fi.Exists) + return Error("File to replace not found."); + + if (!Path.GetExtension(file.FileName).Equals(fi.Extension)) + return Error("Replacement file must have the same extension as the file being replaced."); + + file.SaveAs(fi.FullName); + + return ""; + } - return ""; - } - } + /// + /// Check File Info + /// + /// + /// + /// + private string CheckFile(string path, HttpPostedFileBase file) + { + var result = ""; + if (file == null || file.ContentLength == 0) + result = Error("No file provided."); + + if (!IsInRootPath(path)) + result = Error("Attempt to replace file outside root path"); + + var fileExtension = Path.GetExtension(file.FileName).ToLower(); + + if (IsOnlyImage && !imgExtensions.Contains(fileExtension)) + result = Error("Uploaded file type is not allowed."); + else if (!allowedExtensions.Contains(fileExtension)) + result = Error("Uploaded file type is not allowed."); + + if (LimitFileSizeMB != 0 && file.ContentLength > (LimitFileSizeMB * 1024 * 1024)) + result = Error("Uploaded file size is too large."); + + return result; } } -} +} \ No newline at end of file