List <upload> uploadRemote(string path) { List <upload> list = new List <upload>(); string savePath = PathServerUtility.MapPath(path); //保存文件地址 //目录验证 if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string uri = System.Net.WebUtility.UrlDecode(this.Params("upfile")); string[] imgUrls = null; if (string.IsNullOrEmpty(uri)) { uri = System.Net.WebUtility.UrlDecode(this.Params("upfile[]")); imgUrls = Regex.Split(uri, ",", RegexOptions.IgnoreCase); } else { uri = uri.Replace("&", "&"); imgUrls = Regex.Split(uri, "ue_separate_ue", RegexOptions.IgnoreCase); } for (int i = 0, len = imgUrls.Length; i < len; i++) { try { var imgUrl = imgUrls[i]; var upload = new upload { source = imgUrl, state = "SUCCESS" }; if (!imgUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase) && !imgUrl.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { continue; } //格式验证 int temp = imgUrl.LastIndexOf('.'); var ext = imgUrl.Substring(temp).ToLower(); if (Array.IndexOf(filetype, ext) == -1) { upload.state = "ERROR"; continue; } var stream = HttpUtility.DownBytes(imgUrl); if (stream == null || stream.Length == 0) { continue; } var tmpName = $"{DateTime.Now.ToString("yyyyMMddHHmmssffffff")}_{i}{ext}"; //写入文件 using (FileStream fs = new FileStream(Path.Combine(savePath, tmpName), FileMode.CreateNew)) { //stream.CopyTo(fs); fs.Write(stream, 0, stream.Length); fs.Flush(); } upload.url = PathServerUtility.CombineWithRoot(path, tmpName); list.Add(upload); } catch { } } return(list); }