基于4.0.3修改
要更改的文件如下:
1.upload_json.ashx
Hashtable hash = new Hashtable(); hash["error"] = 0; hash["url"] = fileUrl; hash["filename"] = Path.GetFileName(fileName);//文件名称作为文件说明 hash["ext"] = Path.GetExtension(fileName).Remove(0, 1);//文件类型 context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8"); context.Response.Write(JsonMapper.ToJson(hash)); context.Response.End();
2.insertfile
//第13行后增加 imgPath = self.basePath + 'plugins/insertfile/icons/', imgPreviewPath = self.basePath + 'plugins/insertfile/icons/Preview/', //第31行变更为 '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /><span style="padding-left:5px;"><img name="imgType" src="' + imgPath + 'blank.gif" /></span></div>', //titleBox = K('[name="title"]', div),后增加 imgType = K('[name="imgType"]', div); //urlBox.val(url);后增加 titleBox.val(data.filename); imgType.attr('src',imgPreviewPath + data.ext + '.gif'); //self.insertHtml(html);的上一行改为 var html = '<a href="' + url + '" data-ke-src="' + url + '" target="_blank"><img src="' + imgType.
16*16的图标放在insertfile文件夹下的icons中,32*32的图标放在icons下的preview中
然后分享另外一份方案
在项目开发中,各种需求都有可能被提出来,用Kindeditor作为项目中使用的文本编辑器也是因为其功能之强大。但使用过程中遇到了各种问题,首先是开发@功能时,发现Kindeditor自带的获取光标位置函数有问题(至今还没找到解决办法,准备换百度的编辑器测试一下),然后就是今天这个需求了:文件上传后自动将原文件名添加文件说明中。
编辑器并不自带此功能(话说这个功能真心应该加上)。如下是更改一番后的解决方案:
首先是更改upload_json.php这个文件,将原文件名添加到返回数据中:
echo $json->encode(array('error' => 0, 'url' => $file_url));
改为:
echo $json->encode(array('error' => 0, 'url' => $file_url,'origin_name'=> $file_name));
然后修改编辑器plugins的 insertfile.js文件中的内容:
在if (allowFileUpload) {……}中找到 urlBox.val(url);
下面添加一行:
titleBox.val(data.origin_name);
如果想要浏览添加服务器文件时也自动填充文件名则继续修改如下内容:
在if (allowFileManager) {……}中找到 K(‘[name=”url”]’, div).val(url);
下面添加一行:
K(‘[name=”title”]’, div).val(title);
如上变解决了自动填充文件名的问题。
转载于:https://my.oschina.net/huangfude/blog/150515