0
篇帖子
composer require topthink/think-image
public function upload(Request $request){
// 获取表单上传文件
//$file = $request->file('file');
$file = \think\Image::open(request()->file('editormd-image-file'));
$dirTime = iconv("UTF-8", "GBK", ROOT_PATH . 'public' . DS . 'upload/images/'.date('Ym',time()));
if (file_exists($dirTime));
else
mkdir ($dirTime,0777,true);
$fileUrl = $dirTime. DS .md5(time()).'.jpg';
$width = $file->width();
if ($width >= 1280){
$info = $file->thumb(1280,720)->save($fileUrl);
}else{
$info = $file->save($fileUrl);
}
if ($info) {
$faceurl = strstr($fileUrl,"/upload");
$result = array(
'success'=>1,
'message'=>'上传成功啦!',
'url'=>$faceurl
);
return json_encode($result);
} else {
// 上传失败获取错误信息
$this->error($file->getError());
}
}
<script type="text/javascript">
let testEditor;
$(function() {
testEditor = editormd("test-editormd", {
width: "100%",
height: '60vh',
path : '/static/markdown/lib/',
codeFold : true,
saveHTMLToTextarea : true,
searchReplace : true,
htmlDecode : "style,script,iframe|on*",
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "/admin/base/upload",
});
});
</script>
本博客内所有原创和翻译的文章的版权归本人所有,允许第三方转载,但转载时请务必保留作者名,并注明出处链接,否则本人将保留追究其法律责任的权利。
「人生在世,留句话给我吧」