如何解决ckEditor上传后不显示照片
我尝试使用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 举报,一经查实,本站将立刻删除。