下载兼顾新浪编辑器和kindeditor编辑的图片上传类
在线演示地址:http://www.ykisp.com/pliuy/user/editor.php
下载地址:下载
很多编辑都很不错,但我发现上传类都不是很理想,发上来我自己修改的
兼顾新浪编辑器和kindeditor编辑的图片上传类.
kindeditor编辑器新发布的2.55版载入速度还可以.
================================================================
兼顾新浪编辑器需要修改
新浪在线可视化编辑器PHP版.中相关文件 img.htm
LoadIMG(imgpath,imgTitle,imgHspace,imgAlign,imgVspace,imgBorder, onmousewheelstr,onloadstr,imgWidth,imgHeight){
修改var html = 为:
var html ="<a href='" + imgpath + "' target=_blank><img src='"+ imgpath +"'";
//
if (onmousewheelstr != "") {
html += "onmousewheel='"+ onmousewheelstr +"'";
}
if (onloadstr != "") {
html += "onload='"+ onloadstr +"'";
}
//
if (imgWidth > 0) {
html += "width='"+imgWidth+"'";
}
if (imgHeight > 0) {
html += "height='"+imgHeight+"'";
}
if (imgAlign != "") {
html += "align='"+imgAlign+"'";
}
if (imgHspace > 0) {
html += "hspace='"+imgHspace+"'";
}
if (imgVspace > 0) {
html += "vspace='"+imgVspace+"'";
}
html += "border='"+imgBorder+"'";
html += "alt='"+imgTitle+"'";
html += " /></a>";
}
==================================
==================================
kindeditor编辑器中有设置图片属性表单.
需要修改:kindeditor.js 中:
复制内容到剪贴板
代码:
KindInsertImage(onmousewheelstr,onloadstr,)
//添加
if (onmousewheelstr != "") {
ks.append('" onmousewheel="', onmousewheelstr);
}
if (onloadstr != "") {
ks.append('" onload="', onloadstr);
}
====================================================================
新浪在线可视化编辑器PHP版效果图:
加入了:
$;//CTRL+鼠标滚轮放大或缩小
$;//自动调整图片(指定高和宽这里就没什么用了)
复制内容到剪贴板
代码:
//自动调整缩略图比例
//应用 <img onload="return imgzoom(this,550)" alt="自动调整缩略图比例" src="a.jpg" border="0">
function imgzoom(img,maxsize){
var a=new Image();
a.src=img.src
if(a.width > maxsize * 4)
{
img.style.width=maxsize;
}
else if(a.width >= maxsize)
{
img.style.width=Math.round(a.width * Math.floor(4 * maxsize / a.width) / 4);
}
return false;
}
//CTRL+鼠标滚轮放大或缩小
//应用 <img onmousewheel="return imgzoom_b_s(this);" alt="CTRL+鼠标滚轮放大或缩小" src="logo.jpg" border="0">
function imgzoom_b_s(o) {
if(event.ctrlKey) {
var zoom = parseInt(o.style.zoom, 10) || 100;
zoom -= event.wheelDelta / 12;
if(zoom > 0) {
o.style.zoom = zoom + '%';
}
return false;
} else {
return true;
}
}
PHP代码:
复制PHP内容到剪贴板
PHP代码:
<?php
#*********************************************************
#文件名称: upload.php
#功能描述: 上传文件类
#程序制作:留印(adleyliu)
#联系qq :14339095
#联系邮箱:[email=adleyliu@163.com]adleyliu@163.com[/email]
#官方网站: [url=http://www.115000.com.cn/]http://www.115000.com.cn[/url]
#Copyright (C) 2007-2008 115000.com.cn all rights reserved.
#最后更新: 2007-11-11
#注:转发时请保留此声明信息,这段声明不并会影响你的速度!
#如有修改请将修改后的文件以邮件形式发送给作者一份,谢谢!
#
#*********************************************************
#*********************************************************
#使用方法开始
#*********************************************************
///表单提交:
///<form name="form1" id="form1" method="post" action="upload.php?edittype=1" enctype="multipart/form-data" target="myiframe">
/// edittype=2 动网编辑器 上传功能有时间再弄!:)。
/// edittype=1 新浪编辑器 需要修改img.htm,
/// edittype=0 kindeditor编辑器
//声明一个上传类
$yl_upload = new yl_upload_class();
//设置参数
global $yl_filedata,$yl_directroy,$file_urldirectroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
$yl_filedata = 'fileData';//表单名
$yl_directroy = '../'.$yl_uploadpath.'/news';//上传主目录
$file_urldirectroy = ''.$yl_uploadpath.'/news';//文件url可以是绝对路径
$yl_settingsnew = 'month_'.date('Ym');//上传主目录1按版块存入不同目录,2按月份存入不同目录,3按天存入不同目录
$yl_maxsize = 204800; //这里以字节为单位(1024*2)*1024=2097152 =2M
$yl_sizeformat = 'k'; //显示文件大小单位b字节,k千,m兆
$yl_arrext = array('gif','jpg','jpeg','png','bmp');//允许上传文件类型
$yl_ext = 1; //0原文件类型上传,1统一为存为jpg
global $yl_file_path,$yl_file_nameold,$yl_file_names,$yl_file_size,$yl_file_type;
/*
echo '上传成功';
echo '<br>';
echo '文件目录: $file_urldirectroy;
echo '<br>';
echo '原文件名:'.$yl_file_nameold.'';
echo '<br>';
echo '新文件名:'.$yl_file_names.'';
echo '<br>';
echo '文件大小:'.$yl_file_size.'';
echo '<br>';
echo '文件类型:'.$yl_file_type.'';
*/
global $editor,$imgWidth, $imgHeight, $imgBorder,$imgTitle,$imgAlign,$imgHspace,$imgVspace;
$editor = $_POST['edittype'] ? $_POST['edittype'] : $_GET['edittype'];
$imgWidth = $_POST['imgWidth'];
$imgHeight = $_POST['imgHeight'];
$imgBorder = $_POST['imgBorder'];
$imgTitle = $_POST['imgTitle'];
$imgAlign = $_POST['imgAlign'];
$imgHspace = $_POST['imgHspace'];
$imgVspace = $_POST['imgVspace'];
//上传
$yl_upload -> yl_uploadfile();
#*********************************************************
#使用方法结束
#*********************************************************
#*********************************************************
#类
#*********************************************************
class yl_upload_class
{
#*********************************************************
#创建目录函数
#*********************************************************
function createfolder($yl_path)
{
if (!file_exists($yl_path))
{
$this -> createfolder(dirname($yl_path));
@mkdir($yl_path, 0777);
}
return $this -> createfolder;
}
#*********************************************************
#获取文件名称,大小,类型,临时文件名
#*********************************************************
function yl_getfilename($yl_type)
{
global $yl_filedata,$yl_directroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
return $_FILES[$yl_filedata][$yl_type];
}
#*********************************************************
#获取文件大小
#*********************************************************
function yl_getfilesize()
{
global $editor;
global $yl_filedata,$yl_directroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
if($this -> yl_getfilename('size') == 0){
if ($editor == 0){
die("<script>alert('请选择上传文件!');history.back();</script>");
}elseif ($editor == 1){ die("<script>alert('请选择上传文件!');window.parent.$('divProcessing').style.display='none';history.back();</script>");
exit;
}
}
if($this -> yl_getfilename('size') > $yl_maxsize){
$yl_maxsizek=$yl_maxsize/1024;
if ($editor == 0){ die("<script>alert('上传文件超出限制范围:$yl_maxsizek.K!');history.back();</script>");
}elseif ($editor == 1){ die("<script>alert('
上传文件超出限制范
围:$yl_maxsizek.K!');window.parent.$('divProcessing').style.display='none';
history.back();</script>");
exit;
}
}
}
#*********************************************************
#获得文件扩展名
#*********************************************************
function yl_getfiletype()
{
global $editor;
global $yl_filedata,$yl_directroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
$yl_temp_arr = explode(".", $this -> yl_getfilename('name'));
$yl_file_ext = array_pop($yl_temp_arr);
$yl_file_ext = trim($yl_file_ext);
$yl_file_ext = strtolower($yl_file_ext);
//检查扩展名
if (in_array($yl_file_ext, $yl_arrext) === false) {
if ($editor == 0){
die("<script>alert('上传文件类型被限制!');history.back();</script>");
}elseif ($editor == 1){ die("<script>alert('上传文件类型被限制!');window.parent.$('divProcessing').style.display='none';history.back();</script>");
exit;
}
}
return $yl_file_ext;
}
#*********************************************************
#获取文件宽和高
#*********************************************************
function yl_getimagesize($imgurl,$sizetype)
{
global $yl_filedata;
$yl_getimagesize=getimagesize($imgurl);
return $yl_getimagesize[$sizetype];
}
#*********************************************************
#上传
#*********************************************************
function yl_uploadfile()
{
global $editor;
global $yl_filedata,$yl_directroy,$file_urldirectroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
$yl_file_nameold = $this -> yl_getfilename('name');//原文件名
$yl_file_namenews = date('Ymd').'_'.md5(date('YmdHis'));//重命名
if($yl_ext == 0){
$yl_file_names = $yl_file_namenews.'.'.$this -> yl_getfiletype();//改名
}elseif ($yl_ext == 1){
$yl_file_names = $yl_file_namenews.'.jpg';//统一改名为jpg
}
$yl_tmp_name = $this -> yl_getfilename('tmp_name');//服务器上临时文件名
$yl_file_size = $this -> yl_getfilesize();//获取文件大小
$yl_file_type = $this -> yl_getfiletype();//获取文件类型
$yl_file_path = $yl_directroy.'/'.$yl_settingsnew;//建立一个目录
//检查目录是否存在,不存在则创建
if(@is_dir($yl_file_path) === false) {
$this -> createfolder(''.$yl_file_path.'');//创建目录
}
//检查是否已上传
if(@is_uploaded_file($yl_tmp_name) === false) {
if ($editor == 0)
{
die("<script>alert('文件已上传!');history.back();</script>");
}elseif ($editor == 1){ die("<script>alert('文件已上传!');window.parent.$('divProcessing').style.display='none';history.back();</script>");
exit;
}
}
//检查目录写权限
if (@is_writable($yl_file_path) === false) {
if ($editor == 0)
{
die("<script>alert('上传目录没有写权限!');history.back();</script>");
}elseif ($editor == 1){ die("<script>alert('上传目录没有写权限!');window.parent.$('divProcessing').style.display='none';history.back();</script>");
exit;
}
}
$yl_doupload = @copy($yl_tmp_name, ''.$yl_file_path.'/'.$yl_file_names.'');
if($yl_doUpload === false)
{
if ($editor == 0)
{
die("<script>alert('未知错误,文件上传失败!');history.back();</script>");
}elseif ($editor == 1){ die("<script>alert('未知错误,文件上传失败!');window.parent.$('divProcessing').style.display='none';history.back();</script>");
exit;
}
}
global $imgWidth, $imgHeight, $imgBorder,$imgTitle,$imgAlign,$imgHspace,$imgVspace;
$file_url = $yl_directroy.'/'.$yl_settingsnew.'/'.$yl_file_names;
$onmousewheelstr = "return imgzoom_b_s(this);";//CTRL+鼠标滚轮放大或缩小
if ($imgWidth=='0' || $imgHeight=='0' || $imgWidth==0 || $imgHeight==0){
// $imgWidth = $this -> yl_getimagesize($yl_tmp_name,0);
// $imgHeight = $this -> yl_getimagesize($yl_tmp_name,1);
$imgWidth = '';
$imgHeight = '';
$onloadstr = "return imgzoom(this,550);";//自动调整图片
}else{
$onloadstr = '';
}
//插入图片,关闭层
if ($editor == 0)
{
//kindeditor编辑器
echo '<html>';
echo '<head>';
echo '<title>Insert Image</title>';
echo '<meta http-equiv="content-type" c>';
echo '</head>';
echo '<body>';
echo '<script type="text/javascript">parent.KindInsertImage("'. $onmousewheelstr.'","'.$onloadstr.'","'.$file_url.'","'.$imgWidth.'","'.$imgHeight.'","'.$imgBorder.'","'.$imgTitle.'","'.$imgAlign.'","'.$imgHspace.'","'.$imgVspace.'");</script>';
echo '</body>';
echo '</html>';
}elseif ($editor == 1){
//新浪编辑器
die("<script>window.parent.LoadIMG('../{$file_url}','{$imgTitle}','{$imgHspace}','{$imgAlign}','{$imgVspace}','{$imgBorder}',' $onmousewheelstr','$onloadstr','{$imgWidth}','{$imgHeight}');</script>");
}else{
//可以扩展其它编辑器,有时间我会把动网的编辑器加进来。
echo '请选择编辑器';
}
return;
}
#*********************************************************
#提示
#*********************************************************
function alert($yl_msg)
{
echo '<html>';
echo '<head>';
echo '<title>error</title>';
echo '<meta http-equiv="content-type" c>';
echo '</head>';
echo '<body>';
echo '<script type="text/javascript">alert("'.$yl_msg.'");;</script>';
echo '</body>';
echo '</html>';
exit;
}
}
?>
下载地址:下载