参考:https://www.cnblogs.com/Scholars/p/8968838.html

下载:http://www.wangeditor.com/

前端代码:

<script type="text/javascript">
//下面这两行脚本就是弹出文本框
var E = window.wangEditor
var editor = new E('#editor')
// 上传图片(举例)
editor.customConfig.uploadImgServer = '/upload.ashx' //将网络图片隐藏掉
editor.customConfig.showLinkImg = false // 将 timeout 时间改为 3s
editor.customConfig.uploadImgTimeout = * ; document.getElementById('btn1').addEventListener('click', function () {
// 读取 html
alert(editor.txt.html())
}, false) editor.create();
</script> <body>
<form id="newspost" method="post" action="newspost" enctype="multipart/form-data"> <input type="hidden" id="content" name="content"/>
<div style="padding: 5px 0; color: #ccc"></div>
<div id="editor"></div>
<br/> </form>
<button id="btn1">获取html</button>
</body>

后端代码(一般处理程序):

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web; namespace WebApplication1
{
/// <summary>
/// upload 的摘要说明
/// </summary>
public class upload : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8"; var files = context.Request.Files;
if (files.Count <= )
{
return;
} HttpPostedFile file = files[]; if (file == null)
{
context.Response.Write("error|file is null");
return;
}
else
{
string Url = "http://192.168.0.20:8099/IMG/"; string path = context.Server.MapPath("/Upader/Img/"); //存储图片的文件夹
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
} string originalFileName = file.FileName;
string fileExtension = originalFileName.Substring(originalFileName.LastIndexOf('.'), originalFileName.Length - originalFileName.LastIndexOf('.'));
string currentFileName = (new Random()).Next() + fileExtension; //文件名中不要带中文,否则会出错
//生成文件路径
string imagePath = path + currentFileName; //保存文件
file.SaveAs(imagePath); //获取图片url地址
string imgUrl = "./Upader/Img/" + currentFileName; string Json = "{\"data\": [\"../../" + imgUrl.Replace(@"\", @"/") + "\"],\"errno\":\"0\"}"; //返回图片url地址
context.Response.Write(Json);
return;
}
} public bool IsReusable
{
get
{
return false;
}
} }
} 一般处理程序代码

最新文章

  1. UIViewController生命周期-完整版
  2. 微信企业号开发(1)WebAPI在回调模式中的URL验证
  3. 修改Linux的SSH远程连接端口 技巧
  4. nodejs——qureystring的作用
  5. QT 网络编程一
  6. 【BZOJ】【3550】【ONTAK2010】Vacation
  7. QAQ数论模板笔记√
  8. Servlet &amp; JSP - Filter
  9. http断点续传原理:http头 Range、Content-Range
  10. Java读取本地文件,并显示在JSP文件中
  11. Android Weekly Notes Issue #254
  12. Linux运维工程师应具备哪些技能?
  13. Spring事务,Bean生命周期
  14. 【Leetcode】收集
  15. ubuntu linux修改文件所属用户(owner属主)和组(groud属组、用户组)
  16. Mybaits代码生成使用
  17. RabbitMQ学习以及与Spring的集成(一)
  18. 对Table_locks_immediate值的理解
  19. 趴一趴京东的Ajax动态价格页面
  20. MyBatis初识(通过小实例清晰认识MyBatis)

热门文章

  1. Sass @debug
  2. [CF] 8C Looking for Order
  3. 学习旧岛小程序 (4)封装api 请求
  4. shell第一个脚本
  5. 阿里云吴天议:云原生SDWAN 应用 构建智能化云原生SDWAN生态
  6. 黑苹果 MacOS 10.15 Catalina安装教程
  7. asp.net开发微信公众平台----目录汇总-持续更新
  8. Yii 1.1 常规框架部署和配置
  9. .htaccess 详解
  10. CSU 1556 Jerry&#39;s trouble