سلام
من از کدهای زیر برای افزودن اپلود تصویر در Ck Editor اسفتاده کردم . اما این گزینه به قسمت اپلود تصویر اضافه نمی شه.
[HttpPost] public ActionResult UploadImage(HttpPostedFileBase upload, string CKEditorFuncNum, string CKEditor, string langCode) { string vImagePath = String.Empty; string vMessage = String.Empty; string vFilePath = String.Empty; string vOutput = String.Empty; try { if (upload != null && upload.ContentLength > 0) { var vFileName = DateTime.Now.ToString("yyyyMMdd-HHMMssff") + Path.GetExtension(upload.FileName).ToLower(); var vFolderPath = Server.MapPath("/Upload/"); if (!Directory.Exists(vFolderPath)) { Directory.CreateDirectory(vFolderPath); } vFilePath = Path.Combine(vFolderPath, vFileName); upload.SaveAs(vFilePath); vImagePath = Url.Content("/Upload/" + vFileName); vMessage = "تصویر با موفقیت ذخیره شد"; } } catch { vMessage = "There was an issue uploading"; } vOutput = @"<html><body><script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + vImagePath + "\", \"" + vMessage + "\");</script></body></html>"; return Content(vOutput); }
فایل config.js را درون ckeditor بیابید و دستورات زیر را به آن اضافه نمایید.
config.filebrowserImageUploadUrl = '/Home/UploadImage';
سلام خدمت شما دوست عزیز
یک فایل js به نام config در solution ایجاد کنید و قطعه کد زیر رو درونش قرار بدین :
/** * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ CKEDITOR.editorConfig = function (config) { // Define changes to default configuration here. For example: // config.uiColor = '#AADC6E'; config.contentsLangDirection = 'rtl'; config.language = 'fa'; config.filebrowserImageUploadUrl = '/profile/file-upload'; config.toolbar = 'MyToolbar'; config.toolbar_MyToolbar = [ { name: 'document', items: ['NewPage', 'Preview'] }, /*{ name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },*/ /*{ name: 'editing', items: ['Find', 'Replace', '-', 'SelectAll', '-', 'Scayt'] },*/ { name: 'styles', items: ['Styles', 'Format'] }, { name: 'basicstyles', items: ['Bold', 'Italic', 'Strike', '-', 'RemoveFormat'] }, { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', /*'Blockquote'*/] }, { name: 'links', items: ['Link', 'Unlink'/*, 'Anchor'*/] }/* { name: 'tools', items: ['Maximize', '-', 'About'] },*/, { name: 'insert', items: ['Image'/*, 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak' , 'Iframe'*/] } ]; };
سپس کد زیر رو در صفحه ای که میخواین editor بذارین قرار بدین :
CKEDITOR.replace($(value).prop('id').toString(), { customConfig: '/assets/js/config.js' });
به جای این قسمت :
$(value).prop('id').toString()
آی دی المانی که میخواین editor بشه رو بذارین
کد زیر هم آدرس فایل config رو میخواد :
customConfig: '/assets/js/config.js'
در فایل config هم آدرس ذخیره سازی تصویرتون رو قرار بدین :
config.filebrowserImageUploadUrl = '/profile/file-upload';
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)