125 lines
4.2 KiB
C#
125 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
|
|
using System.IO;
|
|
using System.Net;
|
|
using SuperMap.RealEstate.HousingSecurity.APIPlugs.flashuploader;
|
|
|
|
|
|
namespace SuperMap.RealEstate.HousingSecurity.APIPlugs
|
|
{
|
|
public class UpFlashHelper
|
|
{
|
|
/// <summary>
|
|
/// ueditor配置的简单分隔符(ue_split_ue)
|
|
/// </summary>
|
|
public const string UE_SPLIT_UE = "ue_separate_ue";
|
|
|
|
//private static string[] filetype_img = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" };
|
|
//private static string[] filetype_file = { ".rar", ".doc", ".docx", ".zip", ".pdf", ".txt" };
|
|
//private static string[] filetype_flv = { ".swf", ".mp3", ".mp4", ".flv", ".wmv", ".rmvb", ".mkv" };
|
|
|
|
public static bool TrySaveUpFile(HttpPostedFile postfile, int userid, string username, ref MyUpFileInfo upfileinfo, out string msg)
|
|
{
|
|
return TrySaveUpFile(new HttpPostedFileWrapper(postfile), userid, username, ref upfileinfo, out msg);
|
|
}
|
|
public static bool TrySaveUpFile(HttpPostedFileBase postfilebase, int userid, string username, ref MyUpFileInfo upfileinfo, out string msg)
|
|
{
|
|
msg = string.Empty;
|
|
|
|
//服务端存储(信息记录在数据库,文件记录在硬盘上)
|
|
try
|
|
{
|
|
//【数据库标记上传中】
|
|
saveToDB(ref upfileinfo);
|
|
|
|
string _path = upfileinfo.ServerFullSavePath;
|
|
string _full = upfileinfo.ServerFullSavePathAndFileNameExt;
|
|
|
|
//创建目录
|
|
if (!Directory.Exists(_path))
|
|
{
|
|
Directory.CreateDirectory(_path);
|
|
}
|
|
//保存文件
|
|
postfilebase.SaveAs(_full);
|
|
|
|
if (System.IO.File.Exists(_full))
|
|
{
|
|
//【数据库标记上传成功】
|
|
/*
|
|
* 【暂时屏蔽】
|
|
Ctrl_upfiles.UpdateUpFileStat_upok(_fid);
|
|
*/
|
|
msg = "upload success";
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = "upload error:" + ex.Message;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private static void saveToDB(ref MyUpFileInfo upfileinfo)
|
|
{
|
|
//upfileinfo.Entity.fid = (int)_housepic.HousePic_Id;//must
|
|
}
|
|
|
|
public static bool TrySaveUpFile(byte[] bytes, int userid, string usernick, ref MyUpFileInfo upfileinfo, out string msg)
|
|
{
|
|
msg = string.Empty;
|
|
|
|
//服务端存储(信息记录在数据库,文件记录在硬盘上)
|
|
try
|
|
{
|
|
//【数据库标记上传中】
|
|
saveToDB(ref upfileinfo);
|
|
|
|
string _path = upfileinfo.ServerFullSavePath;
|
|
string _full = upfileinfo.ServerFullSavePathAndFileNameExt;
|
|
|
|
//创建目录
|
|
if (!Directory.Exists(_path))
|
|
{
|
|
Directory.CreateDirectory(_path);
|
|
}
|
|
|
|
//下载并保存文件
|
|
//wc.DownloadFile(imgUrl, _upfileinfo.ServerFullSavePath + _upfileinfo.NewFile_Name);
|
|
using (MemoryStream m = new MemoryStream(bytes))
|
|
{
|
|
using (FileStream fs = new FileStream(_full, FileMode.OpenOrCreate))
|
|
{
|
|
m.WriteTo(fs);
|
|
m.Close();
|
|
fs.Close();
|
|
}
|
|
}
|
|
|
|
if (System.IO.File.Exists(_full))
|
|
{
|
|
//【数据库标记上传成功】
|
|
/*
|
|
* 【暂时屏蔽】
|
|
Ctrl_upfiles.UpdateUpFileStat_upok(_fid);
|
|
*/
|
|
|
|
msg = "upload success";
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = "upload error:" + ex.Message;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |