1.ueditor的附件功能自带上传pdf功能。
然而我使用的是github改装七牛版本的,缺提示 文件类型不允许
这就尴尬了,通过文本搜素,也只能这样了,ueditor的js文件太大了,太复杂了。这个肯定是检测上传配置文件引起的。去看配置文件,发现页没啥问题。php error_log 打印配置项和路由,发现原来这个上传文件统一使用的uploadImg这个路由。
那就在上传图片的配置文件上放开了pdf上传。至此可以上传pdf了。
2.html进行pdf展示。(再放开插入html元素 iframe标签的前提下)
虽然上传成功了,但是pdf是展现为附件的,这样就有点不好了。
通过查看附件html代码,关键词搜索,然后去更改了插入pdf的地方。
截取修改的代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | for (i = 0; i < filelist.length; i++) { item = filelist[i]; icon = iconDir + getFileIcon(item.url); title = item.title || item.url. substr (item.url.lastIndexOf( '/' ) + 1); if (title.indexOf( "pdf" )>0){ html += '<iframe style="width: 100%;height: 600px;border: 0px;overflow: hidden" width="100%" height="500px" src="' +item.url+ '"></iframe>' } else { html += '<p style="line-height: 16px;">' + '<img style="vertical-align: middle; margin-right: 2px;" src="' + icon + '" _src="' + icon + '" />' + '<a style="font-size:12px; color:#0066cc;" href="' + item.url + '" title="' + title + '">' + title + '</a>' + '</p>' ; } } me.execCommand( 'insertHtml' , html); |
完美实现。