问题描述
我尝试使用ckEditor,并且像往常一样,遇到了ckEditer的新问题,即从PC上传图片,而不是从Web浏览器复制/粘贴图片URL。
但是,经过多次尝试,我成功显示了[浏览]按钮,并且可以将图片上传到服务器[让我们说:它们在Web应用程序下的指定文件夹]。无论如何,现在的问题是ckEditor不会返回新的图片URL。
我们将非常感谢您的帮助
<%@ Page Language="VB" Strict="true"%>
<script runat="server">
Sub Page_Load(ByVal o As Object,ByVal e As EventArgs)
' Response.Write(processupload())
Call processupload()
End Sub
' 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 Function processupload() As String
' 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")
'end If
' 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
Dim basePath As String = "C:\\Web Projects\\TextEditors\\upload\\Files\\"
' 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 (/)
Dim baseUrl As String = "/upload/Files/"
' 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)
Dim CKEditor As String = HttpContext.Current.Request("CKEditor")
' required: Function number as indicated by CKEditor.
Dim funcNum As String = HttpContext.Current.Request("CKEditorFuncNum")
' Optional: To provide localized messages
Dim langCode As String = HttpContext.Current.Request("langCode")
' ------------------------
' Data processing
' ------------------------
Dim total As Integer
Try
total = HttpContext.Current.Request.Files.Count
Catch ex As Exception
Return sendError("Error uploading the file")
End Try
If (total = 0) Then
Return sendError("No file has been sent")
End If
If (Not System.IO.Directory.Exists(basePath)) Then
Return sendError("basePath folder doesn't exists")
End If
'Grab the file name from its fully qualified path at client
Dim theFile As HttpPostedFile = HttpContext.Current.Request.Files(0)
Dim strFileName As String = theFile.FileName
If (strFileName = "") Then
Return sendError("File name is empty")
End If
Dim sFileName As String = System.IO.Path.GetFileName(strFileName)
Dim name As String = System.IO.Path.Combine(basePath,sFileName)
theFile.SaveAs(name)
Dim url As String = baseUrl + sFileName.Replace("'","\'")
' ------------------------
' Write output
' ------------------------
'funcNum = "0"
Return "<scr" + "ipt type='text/javascript'> window.parent.CKEDITOR.tools.callFunction(" + funcNum + ",'" + url + "','')</scr" + "ipt>"
End Function
Private Function sendError(ByVal msg As String) As String
Dim funcNum As String = HttpContext.Current.Request("CKEditorFuncNum")
Return "<scr" + "ipt type='text/javascript'> window.parent.CKEDITOR.tools.callFunction(" + funcNum + ",'','" + msg + "')</scr" + "ipt>"
End Function
</script>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)