1 | /* |
---|
2 | * FCKeditor - The text editor for internet |
---|
3 | * Copyright (C) 2003-2005 Frederico Caldeira Knabben |
---|
4 | * |
---|
5 | * Licensed under the terms of the GNU Lesser General Public License: |
---|
6 | * http://www.opensource.org/licenses/lgpl-license.php |
---|
7 | * |
---|
8 | * For further information visit: |
---|
9 | * http://www.fckeditor.net/ |
---|
10 | * |
---|
11 | * "Support Open Source software. What about a donation today?" |
---|
12 | * |
---|
13 | * File Name: Uploader.cs |
---|
14 | * This is the code behind of the uploader.aspx page used for Quick Uploads. |
---|
15 | * |
---|
16 | * File Authors: |
---|
17 | * Frederico Caldeira Knabben (fredck@fckeditor.net) |
---|
18 | */ |
---|
19 | |
---|
20 | using System ; |
---|
21 | using System.Globalization ; |
---|
22 | using System.Xml ; |
---|
23 | using System.Web ; |
---|
24 | |
---|
25 | namespace FredCK.FCKeditorV2 |
---|
26 | { |
---|
27 | public class Uploader : FileWorkerBase |
---|
28 | { |
---|
29 | protected override void OnLoad(EventArgs e) |
---|
30 | { |
---|
31 | // Get the posted file. |
---|
32 | HttpPostedFile oFile = Request.Files["NewFile"] ; |
---|
33 | |
---|
34 | // Check if the file has been correctly uploaded |
---|
35 | if ( oFile == null || oFile.ContentLength == 0 ) |
---|
36 | { |
---|
37 | SendResults( 202 ) ; |
---|
38 | return ; |
---|
39 | } |
---|
40 | |
---|
41 | int iErrorNumber = 0 ; |
---|
42 | string sFileUrl = "" ; |
---|
43 | |
---|
44 | // Get the uploaded file name. |
---|
45 | string sFileName = System.IO.Path.GetFileName( oFile.FileName ) ; |
---|
46 | |
---|
47 | int iCounter = 0 ; |
---|
48 | |
---|
49 | while ( true ) |
---|
50 | { |
---|
51 | string sFilePath = System.IO.Path.Combine( this.UserFilesDirectory, sFileName ) ; |
---|
52 | |
---|
53 | if ( System.IO.File.Exists( sFilePath ) ) |
---|
54 | { |
---|
55 | iCounter++ ; |
---|
56 | sFileName = |
---|
57 | System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) + |
---|
58 | "(" + iCounter + ")" + |
---|
59 | System.IO.Path.GetExtension( oFile.FileName ) ; |
---|
60 | |
---|
61 | iErrorNumber = 201 ; |
---|
62 | } |
---|
63 | else |
---|
64 | { |
---|
65 | oFile.SaveAs( sFilePath ) ; |
---|
66 | |
---|
67 | sFileUrl = this.UserFilesPath + sFileName ; |
---|
68 | break ; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | // added by Junyin.Wu for convert ~ to application path |
---|
73 | sFileUrl = sFileUrl.Replace("~", Request.ApplicationPath); |
---|
74 | |
---|
75 | SendResults( iErrorNumber, sFileUrl, sFileName ) ; |
---|
76 | } |
---|
77 | |
---|
78 | #region SendResults Method |
---|
79 | |
---|
80 | private void SendResults( int errorNumber ) |
---|
81 | { |
---|
82 | SendResults( errorNumber, "", "", "" ) ; |
---|
83 | } |
---|
84 | |
---|
85 | private void SendResults( int errorNumber, string fileUrl, string fileName ) |
---|
86 | { |
---|
87 | SendResults( errorNumber, fileUrl, fileName, "" ) ; |
---|
88 | } |
---|
89 | |
---|
90 | private void SendResults( int errorNumber, string fileUrl, string fileName, string customMsg ) |
---|
91 | { |
---|
92 | Response.Clear() ; |
---|
93 | |
---|
94 | Response.Write( "<script type=\"text/javascript\">" ) ; |
---|
95 | Response.Write( "window.parent.OnUploadCompleted(" + errorNumber + ",'" + fileUrl.Replace( "'", "\\'" ) + "','" + fileName.Replace( "'", "\\'" ) + "','" + customMsg.Replace( "'", "\\'" ) + "') ;" ) ; |
---|
96 | Response.Write( "</script>" ) ; |
---|
97 | |
---|
98 | Response.End() ; |
---|
99 | } |
---|
100 | |
---|
101 | #endregion |
---|
102 | } |
---|
103 | } |
---|