原文链接:八点博客
https://www.badianboke.com/
1、代码
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<title>Simple example - Editor.md examples</title>
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/editormd.css" />
<link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
</head>
<body>
<div id="layout">
<header>
<h1>Simple example</h1>
</header>
<div id="test-editormd">
<textarea style="display:none;">[TOC]#Disabled options</textarea>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/editormd.min.js"></script>
<script type="text/javascript">
var testEditor;
$(function() {
testEditor = editormd("test-editormd", {
width : "90%",
height : 640,
syncScrolling : "single",
path : "lib/",
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "/AEBrvTkjOg.php/ajax/uploadByEditormd", // 文件上传的处理请求!
});
/*
// or
testEditor = editormd({
id : "test-editormd",
width : "90%",
height : 640,
path : "../lib/"
});
*/
});
</script>
</body>
</html>
2、上传图片
$savePath = ROOT_PATH . '\public\uploads\md\\'; //实际保存路径
$saveURL = config('upload.cdnurl') . '/uploads/md/'; //返回路径(带域名)
$formats = array(
'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp')
);
$name = 'editormd-image-file';
if (isset($_FILES[$name]))
{
$imageUploader = new \app\admin\controller\EditormdUploaderReal($savePath, $saveURL, $formats['image']); // Ymdhis表示按日期生成文件名,利用date()函数
$imageUploader->config(array(
//'maxSize' => 1024, // 允许上传的最大文件大小,以KB为单位,默认值为1024
//'cover' => true, // 是否覆盖同名文件,默认为true
));
if ($imageUploader->upload($name))
{
$imageUploader->message('上传成功!', 1);
}
else
{
$imageUploader->message('上传失败!', 0);
}
}
3、示例
点击查看示例