FCKeditor 上傳ftp asp.net
修改FileBrowser/fileworkerbase.cs的FileUpload方法:
protected void FileUpload( string resourceType, string currentFolder, bool isQuickUpload )
{
HttpPostedFile File = Request.Files[ "NewFile" ];
System.Drawing.Image img = System.Drawing.Image.FromStream(oFile.InputStream);
string sFileName = "";
if ( File == null )
{
this.SendFileUploadResponse( 202, isQuickUpload );
return;
}
// Map the virtual path to the local server path.
string sServerDir = this.ServerMapFolder( resourceType, currentFolder, isQuickUpload );
// Get the uploaded file name.
sFileName = System.IO.Path.GetFileName( oFile.FileName );
sFileName = this.SanitizeFileName( sFileName );
string sExtension = System.IO.Path.GetExtension( oFile.FileName );
sExtension = sExtension.TrimStart( '.' );
if ( !this.Config.TypeConfig[ resourceType ].CheckIsAllowedExtension( sExtension ) )
{
this.SendFileUploadResponse( 202, isQuickUpload );
return;
}
if ( this.Config.CheckIsNonHtmlExtension( sExtension ) && !this.CheckNonHtmlFile( oFile ) )
{
this.SendFileUploadResponse( 202, isQuickUpload );
return;
}
int iErrorNumber = 0;
int iCounter = 0;
string date = DateTime.Now.ToString("yyyyMMddhhmmss");
string sFileNameAll = System.IO.Path.GetFileName(oFile.FileName);
string imageFullName = date + "_" + sFileNameAll;
string rginalNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(imageFullName);
while ( true )
{
string sFilePath = System.IO.Path.Combine(sServerDir, imageFullName);
if ( System.IO.File.Exists( sFilePath ) )
{
iCounter++;
imageFullName =
orginalNameWithoutExt +
"(" + iCounter + ")." +
sExtension;
iErrorNumber = 201;
}
else
{
bool con = ftpuploadAll(img, image_xq + imageFullName);//上傳到ftp
if (con == false)
{
iErrorNumber = 400;
}
else
{
oFile.SaveAs(sFilePath);//上傳到本地
iErrorNumber = 0;
}
break;
}
}
TypeConfig typeConfig = this.Config.TypeConfig[resourceType] ;
string sFileUrl = isQuickUpload ? typeConfig.GetQuickUploadPath() : typeConfig.GetFilesPath() ;
sFileUrl += imageFullName;
this.SendFileUploadResponse(iErrorNumber, isQuickUpload, sFileUrl, imageFullName);
}
FTP方法:
在webconfig配置ftp的資訊,在這裡呼叫
public static readonly string ftpuser = ConfigurationManager.AppSettings["ftp_user"].ToString();//ftp user
public static readonly string ftppassword = ConfigurationManager.AppSettings["ftp_password"].ToString();//ftp password
public static readonly string image_xq = ConfigurationManager.AppSettings["image_xq"].ToString();//ftp address
public bool ftpuploadAll(System.Drawing.Image image, string uri)
{
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential(ftpuser, ftppassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
//例項化流
MemoryStream imageStream = new MemoryStream();
//將圖片的例項儲存到流中
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
//儲存流的二進位制陣列
byte[] imageContent = new Byte[imageStream.Length];
imageStream.Position = 0;
//將流瀉如陣列中
imageStream.Read(imageContent, 0, (int)imageStream.Length);
byte[] buff = imageStream.ToArray();
try
{
Stream strm = reqFTP.GetRequestStream();
strm.Write(buff, 0, buff.Length);
strm.Close();
}
catch (Exception ex)
{
return false;
}
return true;
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22392018/viewspace-711710/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- fckeditor上傳突破_方法
- 定時ftp上傳,如何設定定時ftp上傳檔案FTP
- fckeditor<=2.6.4任意檔案上傳漏洞
- ftp上傳軟體,好用的ftp上傳軟體,使用方法FTP
- PHP ftp上傳檔案PHPFTP
- ftp上傳工具下載,ftp上傳工具下載使用教程,Linux如何配置ftp伺服器?FTPLinux伺服器
- c# 上傳FTP檔案C#FTP
- asp.net文字編輯器(FCKeditor)ASP.NET
- ASP.NET中配置FCKeditor2.63ASP.NET
- expdp備份+FTP自動上傳FTP
- 利用ftp自動上傳檔案FTP
- 從ftp上傳下載檔案(二)FTP
- 從ftp上傳下載檔案(一)FTP
- C# FTP 上傳 下載(彙總)C#FTP
- C# FTP上傳下載(支援斷點續傳)C#FTP斷點
- C# 上傳下載ftp(支援斷點續傳)C#FTP斷點
- Windows 機器通過 FTP 上傳檔案WindowsFTP
- FTP上傳檔案速度太慢怎麼辦?FTP
- Qt5.X FTP上傳與下載QTFTP
- Java上傳檔案到ftp伺服器JavaFTP伺服器
- php通過ftp協議上傳檔案PHPFTP協議
- ftp上傳的檔案指定許可權FTP
- ASP.NET WebApi 圖片上傳ASP.NETWebAPI
- ASP.NET Core 檔案上傳ASP.NET
- Linux基礎命令---mput上傳ftp檔案LinuxFTP
- 用ASP.NET上傳大檔案ASP.NET
- Linux下透過FTP上傳資料備份LinuxFTP
- 如何快速提升ftp的上傳速度_from_windows_to_solarisFTPWindows
- ASP.NET MVC+LayUI視訊上傳ASP.NETMVCUI
- ASP.NET Ueditor上傳圖片新增水印ASP.NET
- asp.net上傳圖片生成縮圖ASP.NET
- ASP.NET MVC實踐系列11-FCKEditor和CKEditor的使用ASP.NETMVC
- FTP MPUT 關閉互動同時上傳多檔案FTP
- 用java+ftp實現檔案上傳的問題?JavaFTP
- Linux ftp 自動上傳備份檔案指令碼LinuxFTP指令碼
- C# FTP上傳檔案至伺服器程式碼C#FTP伺服器
- AS/400上的FTPFTP
- FCKeditor2.2無法使用上傳功能的解決!