Browse Source

修改文件路径拼接方式

develop-FileUpload-test
胡超1 2 years ago
parent
commit
523e41d766
  1. 26
      24Hour/Controllers/Common/CommonController.cs

26
24Hour/Controllers/Common/CommonController.cs

@ -22,6 +22,7 @@ using Quartz.Logging;
using SqlSugar; using SqlSugar;
using sun.security.x509; using sun.security.x509;
using System.Drawing.Printing; using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Security.AccessControl; using System.Security.AccessControl;
using static com.sun.tools.@internal.xjc.reader.xmlschema.bindinfo.BIConversion; using static com.sun.tools.@internal.xjc.reader.xmlschema.bindinfo.BIConversion;
using static javax.jws.soap.SOAPBinding; using static javax.jws.soap.SOAPBinding;
@ -2755,9 +2756,9 @@ namespace _24Hour.Controllers.Common
if (System.IO.File.Exists(filename)) if (System.IO.File.Exists(filename))
{ {
filename = filename.Replace(@"\\",@"\"); filename = filename.Replace(@"\\", @"\");
var data = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot"); var data = System.IO.Path.Combine(Environment.CurrentDirectory, "wwwroot");
if (filename.Contains(data)==false) if (filename.Contains(data) == false)
{ {
return BadRequest(); return BadRequest();
} }
@ -2796,7 +2797,7 @@ namespace _24Hour.Controllers.Common
var fname = $@"{file.FileName}"; var fname = $@"{file.FileName}";
var hzname = $"{Path.GetExtension(fname)}"; var hzname = $"{Path.GetExtension(fname)}";
if (AllowedExtensions.Contains(hzname.ToLower()) == false) if (AllowedExtensions.Contains(hzname.ToLower()) == false)
{ {
outParm.IsSucceed = false; outParm.IsSucceed = false;
@ -2850,8 +2851,8 @@ namespace _24Hour.Controllers.Common
{ {
Result result = new Result(); Result result = new Result();
var urlpath = file.Replace("/", @"\"); var urlpath = file.Split('/');
var path = Path.Combine(Environment.CurrentDirectory, "wwwroot" + urlpath); var path = Path.Combine(Environment.CurrentDirectory, "wwwroot", Path.Combine(urlpath));
if (System.IO.File.Exists(path)) if (System.IO.File.Exists(path))
{ {
var str = Elight.Utility.Encrypt.DataEncryption.Decryptiones(path); var str = Elight.Utility.Encrypt.DataEncryption.Decryptiones(path);
@ -2875,11 +2876,13 @@ namespace _24Hour.Controllers.Common
{ {
try try
{ {
var islinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
//根据输入url获取base64值 //根据输入url获取base64值
var getstr = (string s) => var getstr = (string s) =>
{ {
var urlpath = s.Replace("/", @"\"); var urlpath = s.Split('/');
var path = Path.Combine(Environment.CurrentDirectory, "wwwroot" + urlpath);
var path = Path.Combine(Environment.CurrentDirectory, "wwwroot" , Path.Combine(urlpath));
if (System.IO.File.Exists(path)) if (System.IO.File.Exists(path))
{ {
return Elight.Utility.Encrypt.DataEncryption.Decryptiones(path); return Elight.Utility.Encrypt.DataEncryption.Decryptiones(path);
@ -2892,19 +2895,20 @@ namespace _24Hour.Controllers.Common
//根据输入url获取文件是否存在 //根据输入url获取文件是否存在
var getexist = (string s) => var getexist = (string s) =>
{ {
var urlpath = s.Replace("/", @"\");
var path = Path.Combine(Environment.CurrentDirectory, "wwwroot" + urlpath); var urlpath = s.Split('/');
var path = Path.Combine(Environment.CurrentDirectory, "wwwroot", Path.Combine(urlpath));
return System.IO.File.Exists(path); return System.IO.File.Exists(path);
}; };
var data = file.Select(x => new var data = file.Select(x => new
{ {
Item = x, Item = x,
IsExist = getexist(x), IsExist = getexist(x),
BaseStr = getstr(x) BaseStr = getstr(x),
}); });
result.IsSucceed = true; result.IsSucceed = true;
result.result = data; result.result = data;
} }
catch catch
{ {

Loading…
Cancel
Save