-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathupload.aspx
More file actions
94 lines (73 loc) · 3.37 KB
/
Copy pathupload.aspx
File metadata and controls
94 lines (73 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<%@ Page Language="C#" Strict="true"%>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(processUpload());
}
// Upload script for CKEditor.
// Use at your own risk, no warranty provided. Be careful about who is able to access this file
// The upload folder shouldn't be able to upload any kind of script, just in case.
// If you're not sure, hire a professional that takes care of adjusting the server configuration as well as this script for you.
// (I am not such professional)
private String processUpload()
{
// Step 1: change the true for whatever condition you use in your environment to verify that the user
// is logged in and is allowed to use the script
if (true)
return sendError("You're not allowed to upload files");
// Step 2: Put here the full absolute path of the folder where you want to save the files:
// You must set the proper permissions on that folder
String basePath = "D:\\CKFinder\\ckfinder\\userfiles\\";
// Step 3: Put here the Url that should be used for the upload folder (it the URL to access the folder that you have set in $basePath
// you can use a relative url "/images/", or a path including the host "http://example.com/images/"
// ALWAYS put the final slash (/)
String baseUrl = "/ckfinder/userfiles/";
// Done. Now test it!
// No need to modify anything below this line
//----------------------------------------------------
// ------------------------
// Input parameters: optional means that you can ignore it, and required means that you
// must use it to provide the data back to CKEditor.
// ------------------------
// Optional: instance name (might be used to adjust the server folders for example)
String CKEditor = HttpContext.Current.Request["CKEditor"] ;
// Required: Function number as indicated by CKEditor.
String funcNum = HttpContext.Current.Request["CKEditorFuncNum"] ;
// Optional: To provide localized messages
String langCode = HttpContext.Current.Request["langCode"] ;
// ------------------------
// Data processing
// ------------------------
int total;
try
{
total = HttpContext.Current.Request.Files.Count;
}
catch (Exception e)
{
return sendError("Error uploading the file");
}
if (total==0)
return sendError("No file has been sent");
if (!System.IO.Directory.Exists(basePath))
return sendError("basePath folder doesn't exists");
//Grab the file name from its fully qualified path at client
HttpPostedFile theFile = HttpContext.Current.Request.Files[0];
String strFileName = theFile.FileName;
if (strFileName=="")
return sendError("File name is empty");
String sFileName = System.IO.Path.GetFileName(strFileName);
String name = System.IO.Path.Combine(basePath, sFileName);
theFile.SaveAs(name);
String url = baseUrl + sFileName.Replace("'", "\'");
// ------------------------
// Write output
// ------------------------
return "<scr" + "ipt type='text/javascript'> window.parent.CKEDITOR.tools.callFunction(" + funcNum + ", '" + url + "', '')</scr" + "ipt>";
}
private String sendError(String msg)
{
String funcNum = HttpContext.Current.Request["CKEditorFuncNum"] ;
return "<scr" + "ipt type='text/javascript'> window.parent.CKEDITOR.tools.callFunction(" + funcNum + ", '', '" + msg + "')</scr" + "ipt>";
}
</script>