Posts Tagged ‘fckeditor’

Fckeditor 修改上传路径以及上传自动更改名称

星期二, 08月 5th, 2008

测试版本:Fckeditor 2.6.3 beta

1.一般情况下,fckeditor上传文件是指定目录(我们这里假设上传到uploads目录中),但是在实际开发中,可能程序会运行在二级目录,http://www.domain.com/app/ 下,在一级目录文件以及目录不能增加或修改的情况下,那我们又得去修改fckeditor里的config.php文件设置上传文件夹,这在很多开源程序中意义重大,拿一个程序来说,我上传的文件永远会在这个目录里中的 uploads 文件夹中。不管我们把这个程序移动到任何子目录中都不需要修改,当然如果你要把uploads文件夹改成其他名字,也很方便。代码如下:

1
2
3
4
5
6
$tmp_workroot = '../../../../../../'; //设置此虚拟目录根路径
$tmp_path = realpath($tmp_workroot).'\uploads\\'; //得到绝对路径和合并上传目录
 
//$tmp_abs_path = str_replace('\\','\\\\',$tmp_path); //得到fckeditor接受的绝对路径地址,如果要使用绝对路径上传,程序运行在windows操作系统要用到此代码
$tmp_siteroot = str_replace('/','\\',$_SERVER['DOCUMENT_ROOT']);	//得到根目录并转换
$tmp_relative_path = str_replace('\\','/',str_replace($tmp_siteroot,'',$tmp_path)); //得到相对上传路径

把上面这段代码添加到 fckeditor\editor\filemanager\connectors\php\config.php 顶部,然后把
$Config['UserFilesPath'] = ‘/uploads/’ ;
改成:$Config['UserFilesPath'] = $tmp_relative_path ;
工作就完成了

2.自动更名
打开fckeditor\editor\filemanager\connectors\php\commands.php 文件
修改$sFileName = time().mt_rand().’.’.$sExtension; //这是我的文件名,格式是:unix时间戳+随机数+扩展名
你可以展开你天马行空的想象力去命令,例如按年、月、日目录分类

把Fckeditor整合到Zend Framework View_Helper里

星期一, 08月 4th, 2008

看到过把fckeditor放进Controller和直接放在模板里的,虽然能成功运行,但总感觉都和Zend Framework规范有点不太相符,个人觉得放在视图助手里科学一点。

Zend Framework v1.52
Fckeditor v2.6.3 beta

其中fckeditor放在public/js/fckeditor目录下

代码如下:

[-]View Code LANGUAGE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
< ?php
/**************************
@Author  : evila
@Update  :
@Content : Fckeditor 视图辅助类
**************************/
 
class Zend_View_Helper_Fckeditor
{
 function fckeditor($InstanceName='',$value='',$width=800,$height=500,$toolbar='Default')
 {
  require_once 'js/fckeditor/fckeditor.php'
  $iFCKeditor = new FCKeditor($InstanceName)
  $iFCKeditor-&gtBasePath = './js/fckeditor/'
  $iFCKeditor-&gtWidth  = "$width"
  $iFCKeditor-&gtHeight = "$height"
        $iFCKeditor-&gtValue = "$value"
  $iFCKeditor-&gtToolbarSet = "$toolbar"
 
  return $iFCKeditor-&gtCreateHtml()
 }
}

在模板文件里只需 <?php echo $this->fckeditor(’InstanceName’,'test_text’);?> 调用即可(参数自行输入)。
插件fckeditor引导文件 require_once ‘js/fckeditor/fckeditor.php’; 也可用Zend::Loader()加载,但是根据官方手册介绍,效率是一样的