前瞻:tinymce富文本编辑器上传多媒体默认是复制视频链接,不能本地直接上传,下面的方法是拉起本地上传后把链接赋值到链接
- 编辑Dcatadmin集成的editor
$form->editor('content')->options([ | |
'file_picker_types'=> 'media', | |
'file_picker_callback'=>JavaScript::make(<<<JS | |
//为不同插件指定文件类型及后端地址 | |
switch(meta.filetype){ | |
case 'media': | |
filetype='.mp3, .mp4'; | |
upurl='/api/v1/upload/video'; | |
break; | |
case 'file': | |
default: | |
} | |
//模拟出一个input用于添加本地文件 | |
var input = document.createElement('input'); | |
input.setAttribute('type', 'file'); | |
input.setAttribute('accept', filetype); | |
input.click(); | |
input.onchange = function() { | |
var file = this.files[0]; | |
var formData; | |
console.log(file.name); | |
formData = new FormData(); | |
formData.append('file', file, file.name ); | |
$.ajax({ | |
url:upurl, /*接口域名地址*/ | |
type:'post', | |
data: formData, | |
contentType: false, | |
processData: false, | |
success:function(res){ | |
console.log(res.data); | |
callback(res.data.url); | |
} | |
}) | |
} | |
JS), | |
]); |