为 KindEditor 实现图片上传


 用 Lysee 开发了一个 BBS,发贴和回复用的是 KindEditor ,图片上传这块用 Lysee 照抄了 upload.php,经测试没有问题,发上来大家看看。

  Html代码   

<html> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8">'; 
<title>{:bbsys::SITE_NAME:} - Insert Image</title> 
</head> 
<body>  
<!--{: 
string image_save_path(string file_sum) 
{ 
 int hv = file_sum.hash(); 
 string rv = format("%.3d", [(hv % 256) + 1]); 
 string sv = format("%.3d", [(hv \ 256) % 256 + 1]); 
 string path = incPD(web_upload_path + rv) + sv; 
 sys::mkdir(path); 
 return incPD(path); 
} 
 
string img_URL = "";  
string tmp_file = ${request.imgFile->file}; 
string ext = ${request.imgFile}.fileExt().lower(); 
if (ext in [".jpg", ".jpeg", ".png", ".gif"]) { 
 string sum = tmp_file.md5sum(true); 
 string path = image_save_path(sum); 
 string img_file = path + sum + ext; 
 if (isfile(img_file) or sys::cp(tmp_file, img_file)) 
  img_URL = veryUD(img_file.copy(length(web_path), length(img_file))); 
} 
 
= """<script language="javascript">"""; 
= (img_URL) ? @"""parent.KE.plugin["image"].insert("%{request.id}", 
         "%(img_URL)", "%{request.imgTitle}", "%{request.imgWidth}", 
         "%{request.imgHeight}", "%{request.imgBorder}");""" 
       :"""alert("Failed inserting image!");history.back();"""; 
= """</script>"""; 
:}--> 
</body> 
</html>


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3