论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Access数据库教程
Tag:2000,2003,2007,查询,sql,,教程,安全,转换,排序,复制,删除,修改,视频教程

fckeditor的查看、重命名、删除功能

文章类别:Access数据库 | 发表日期:2010-1-29 15:04:23

有些时候上传了个测试的文件,但fckeditor原版又没有删除的功能,于是我写了一个fckeditor的扩展功能,具有:查看/重命名/删除文件的功能,下面的方法不存在中文乱码的问题(至少我用IE6,IE8,FF3没测出来)。
看图:

1。 第一步 找到这个文件 /fckeditor\editor\filemanager\browser\default\frmresourceslist.html

将已经存在的代码修改为:
复制内容到剪贴板代码:
oListManager.GetFolderRowHtml = function( folderName, folderPath )
{
// Build the link to view the folder.
var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath( folderPath ) + '\');return false;"><img alt="" src="images/Folder.gif" width="16" height="16" border="0"> ' ;

var rLink = '<a href="#" title="Rename Folder" onclick="RenameFolder(\'' + folderName + '\');return false;"><img src="images/rename.gif" width="16" height="16" border="0" alt="Rename Folder" title="Rename Folder"></a>' ;

var dLink = '<a href="#" title="Delete Folder" onclick="DeleteFolder(\'' + folderName + '\');return false;"><img src="images/delete.gif" width="16" height="16" border="0" alt="Delete Folder" title="Delete Folder">' ;

    var ssLink =  rLink + dLink;
return '<tr>' +
   '<td width="16"><\/td><td nowrap>&nbsp;' +
    sLink +
    folderName +
    '<\/a></td><td align="right" nowrap>' + ssLink +
  '<\/td><\/tr>' ;
}

oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )
{
var sIcon = oIcons.GetIcon( fileName ) ;

// Build the link to view the file.
var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;"><img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"> ' ;

var vLink = '<a href="' + ProtectPath( fileUrl ) + '" target="_blank"" title="View file"><img src="images/view.gif" width="16" height="16" border="0" alt="View File" title="View File"></a>' ;

var rLink = '<a href="#" title="Rename file" onclick="RenameFile(\'' + fileName + '\');return false;"><img src="images/rename.gif" width="16" height="16" border="0" alt="Rename File" title="Rename File"></a>' ;

var dLink = '<a href="#" title="Delete file" onclick="DeleteFile(\'' + fileName + '\');return false;"><img src="images/delete.gif" width="16" height="16" border="0" alt="Delete File" title="Delete File"></a>' ;


// Get the file icon.
    var ssLink =  vLink + rLink + dLink;
return '<tr>' +
   '<td width="16"><\/td><td>&nbsp;' +
    sLink +
    fileName +
    '<\/a>' +
   '<\/td><td align="right" nowrap>&nbsp;' +
    fileSize +
    ' KB' + ssLink +
  '<\/td><\/tr>' ;
}

function OpenFolder( folderPath )
{
// Load the resources list for this folder.
window.parent.frames['frmFolders'].LoadFolders( (folderPath) ) ;
}

function OpenFile( fileUrl )
{
window.top.opener.SetUrl( fileUrl.replace( '#', '%23' ) ) ;
window.top.close() ;
window.top.opener.focus() ;
}

function DeleteFolder( folderUrl )
{
if ( !confirm( 'Do you really delete the folder "' + folderUrl + '" ?' ) ) return false;

oConnector.SendCommand( 'DeleteFolder', 'FolderName=' + ( encodeURI(folderUrl) ) , DeleteFolderCallBack ) ;
}

function DeleteFolderCallBack( fckXml )
{
var oNode = fckXml.SelectSingleNode( 'Connector/Error' ) ;
var iErrorNumber = parseInt( oNode.attributes.getNamedItem('number').value ) ;
var sErrorDescription = String( oNode.attributes.getNamedItem('originalDescription').value ) ;

switch ( iErrorNumber )
{
  case 0 :
   Refresh() ;
   break ;
  case 201 :
   alert( 'You have no permissions to delete the folder' ) ;
   break ;
  case 202 :
   alert( 'Invalid folder name' + sErrorDescription ) ;
   break ;
  case 203 :
   alert( 'Folder not exists' + sErrorDescription ) ;
   break ;
  default :
   alert( 'Error deleting folder. \nError number: ' + iErrorNumber  + ' \nError description: ' + sErrorDescription ) ;
   break ;
}
}

function DeleteFile(fileUrl)
{
if ( !confirm( 'Do you really delete the file "' + fileUrl + '" ?' ) ) return false;

oConnector.SendCommand( 'DeleteFile', 'FileName=' + encodeURI( fileUrl ) , DeleteFileCallBack ) ;
}

function DeleteFileCallBack( fckXml )
{
var oNode = fckXml.SelectSingleNode( 'Connector/Error' ) ;
var iErrorNumber = parseInt( oNode.attributes.getNamedItem('number').value ) ;
var sErrorDescription = String( oNode.attributes.getNamedItem('originalDescription').value ) ;

switch ( iErrorNumber )
{
  case 0 :
   Refresh() ;
   break ;
  case 301 :
   alert( 'You have no permissions to delete the file' ) ;
   break ;
  case 302 :
   alert( 'Invalid file name' + sErrorDescription ) ;
   break ;
  case 303 :
   alert( 'File not exists' + sErrorDescription  ) ;
   break ;
  default :
   alert( 'Error deleting file. \nError number: ' + iErrorNumber  + ' \nError description: ' + sErrorDescription ) ;
   break ;
}
}

function RenameFolder( folderName )
{
var newName = prompt('Please enter the new folder name for "' + folderName + '":', folderName);

if ((newName != null) && (newName != '') && (newName != folderName)) {
  oConnector.SendCommand( 'RenameFolder', "FolderName=" + encodeURI(folderName) + "&NewName=" + encodeURI ( newName ), RenameFolderCallBack ) ;
}
}

function RenameFolderCallBack( fckXml )
{
var oNode = fckXml.SelectSingleNode( 'Connector/Error' ) ;
var iErrorNumber = parseInt( oNode.attributes.getNamedItem('number').value ) ;
var sErrorDescription = String( oNode.attributes.getNamedItem('originalDescription').value ) ;

switch ( iErrorNumber )
{
  case 0 :
   Refresh() ;
   break ;
  case 401 :
   alert( 'You have no permissions to rename the folder' ) ;
   break ;
  case 402 :
   alert( 'Invalid folder name' + sErrorDescription ) ;
   break ;
  case 403 :
   alert( 'is not Folder' + sErrorDescription ) ;
   break ;
  case 404 :
   alert( 'Folder not exists' + sErrorDescription ) ;
   break ;
  default :
   alert( 'Error renaming folder. \nError number: ' + iErrorNumber  + ' \nError description: ' + sErrorDescription ) ;
   break ;
}
}

function RenameFile( fileName )
{
var newName = prompt('Please enter the new file name for "' + fileName + '":', fileName);

if ((newName != null) && (newName != '') && (newName != fileName)) {
  oConnector.SendCommand( 'RenameFile', "FileName=" + encodeURI( fileName ) + "&NewName=" + encodeURI( newName ), RenameFileCallBack ) ;
}
}

function RenameFileCallBack( fckXml )
{
var oNode = fckXml.SelectSingleNode( 'Connector/Error' ) ;
var iErrorNumber = parseInt( oNode.attributes.getNamedItem('number').value ) ;
var sErrorDescription = String( oNode.attributes.getNamedItem('originalDescription').value ) ;

switch ( iErrorNumber )
{
  case 0 :
   Refresh() ;
   break ;
  case 501 :
   alert( 'You have no permissions to rename the file' ) ;
   break ;
  case 502 :
   alert( 'Invalid file name' + sErrorDescription ) ;
   break ;
  case 503 :
   alert( sErrorDescription +  'is not a file' ) ;
   break ;
  case 504 :
   alert( 'File not exists' + sErrorDescription  ) ;
   break ;
  default :
   alert( 'Error renaming file. \nError number: ' +  ' \nError description: ' + sErrorDescription ) ;
   break ;
}
}
2。 第二步 找到这个文件 /fckeditor\editor\filemanager\browser\default\frmfolders.html
  将函数OpenFolder(folderPath)最后一句修改为:
复制内容到剪贴板代码:
var agent = navigator.userAgent;
if(agent.indexOf('MSIE') != -1 || agent.indexOf('Trident') != -1) {
    window.parent.frames['frmResourcesList'].LoadResources( oConnector.ResourceType, (folderPath) ) ;
}else{
    window.parent.frames['frmResourcesList'].LoadResources( oConnector.ResourceType, encodeURI(folderPath) ) ;
}
3。第三步,找到fckeditor\editor\filemanager\browser\default\browser.html

添加函数:
复制内容到剪贴板代码:
function selectBrowser(str) {
  var agent = navigator.userAgent;
  if(agent.indexOf('Gecko') != -1) {
     return encodeURIComponent(str);
  }else if(agent.indexOf('MSIE') != -1 || agent.indexOf('Trident') != -1) {
     return str;
  }else{
     return encodeURIComponent(str);
  }
}
第79行修改为: oConnector.ConnectorUrl += 'ServerPath=' + selectBrowser( sServerPath ) + '&' ;
第91行修改为: sUrl += '&CurrentFolder=' + selectBrowser( this.CurrentFolder ) ;

4。第四步 再找这个文件 \fckeditor\editor\filemanager\connectors\php\commands.php
添加:
复制内容到剪贴板代码:
  header('Content-Type:text/html;charset=UTF-8');
function DeleteFolder( $resourceType, $currentFolder ) {
$sFolderName = $_GET['FolderName'];
$sErrorMsg      = '';
$sServerDir = ServerMapFolder( $resourceType, $currentFolder . "/" . $sFolderName ,'DeleteFolder');
    /*if(empty($_cookie[xxxxxx])) {
  $sErrorNumber    = "201"; //permissions
}else */ if(empty($_GET['FolderName']) or (!is_dir($sServerDir))) {
  $sErrorNumber    = "202";  //Invalid Folder Name.
  $sErrorMsg         =  $sFolderName;
}else    if(!file_exists($sServerDir)) {
  $sErrorNumber    = "203"; // Folder not exists
  $sErrorMsg         =  $sFolderName;
  echo $sFolderName;exit();
    }else{
     if(@rmdir($sServerDir)) {
     $sErrorNumber = "0";//success
     }else{
     $sErrorNumber = "222";
     $sErrorMsg    = "目录删除失败,原因:1。目录不为空\n2。没有权限";
     }
}
echo '<Error number="' . $sErrorNumber . '" originalDescription="' . ConvertToXmlAttribute( $sErrorMsg ) . '" />' ;
}

function DeleteFile( $resourceType, $currentFolder ) {
$sFileName     = iconv("utf-8","gbk",$_GET['FileName']);
$sErrorMsg            = "";

$sServerDir = ServerMapFolder( $resourceType, $currentFolder . "/" . $sFileName ,'DeleteFile');
/*if(empty($_COOKIE['hazysuser'])) {
     $sErrorNumber   = "301";  //Security Error.
}else*/ if( empty($_GET['FileName']) or (!is_file($sServerDir))) {
  $sErrorNumber   = "302"; //Invalid File Name.
  $sErrorMsg        = $sFileName;
}else if(!file_exists($sServerDir)) {
  $sErrorNumber   = "303"; //File not exists.
  $sErrorMsg        = $sFileName;
}else{
        if(@unlink($sServerDir)) {
     $sErrorNumber  = "0";
  }else{
     $sErrorNumber  = "333";
           $sErrorMsg     = "无法删除此文件,原因:\n1。没有权限。\n2。必须在DOS下才能删除的特殊文件";
  }
}
echo '<Error number="' . $sErrorNumber . '"  originalDescription="' . ConvertToXmlAttribute( $sErrorMsg ) . '" />';
}

function RenameFolder( $resourceType, $currentFolder ) {
    $sErrorMsg   = '';
$sFolderName = urldecode(mb_convert_encoding($_GET['FolderName'],"gbk","utf-8"));
$sNewName  = urldecode(mb_convert_encoding($_GET['NewName'],"gbk","utf-8"));
$sServerDir  = ServerMapFolder( $resourceType, $currentFolder . "/" . $sFolderName ,'RenameFolder');
$sNewDir  = ServerMapFolder( $resourceType, $currentFolder . "/" . $sNewName ,'RenameFolder' );
   
   
    /*if( empty($_COOKIE[xxxxxx])) {
  $sErrorNumber   = "401";
}else */if ( empty($_GET['FolderName']) or  empty($_GET['NewName']) ) {
  $sErrorNumber = "402";//Invalid Folder Name.
  $sErrorMsg      = $sFolderName .' != '.$sNewName;
/*}else if (!is_dir($sServerDir)) {
        $sErrorNumber = "403";  //is not Folder
  $sErrorMsg    = $sFolderName.' is not Folder';
}else if (!file_exists($sServerDir)) {
   $sErrorNumber = "404";  //Folder not exists.
   $sErrorMsg    = $sFolderName;*/
}else {
  if(rename($sServerDir,$sNewDir,stream_context_create() )) {
     $sErrorNumber = "0";
  }else{
     $sErrorNumber = "444";
           $sErrorMsg = "无法修改目录名称:".$sFolderName.'为'.$sNewName.'。';
  }
}
echo '<Error number="' . $sErrorNumber . '"  originalDescription="' . ConvertToXmlAttribute( $sErrorMsg ) . '" />';
}

function RenameFile( $resourceType, $currentFolder ) {
$sFileName = iconv("utf-8","gbk",$_GET['FileName']);
$sNewName = iconv("utf-8","gbk",$_GET['NewName']);
$sErrorMsg  = '';
$sServerDir = ServerMapFolder( $resourceType, $currentFolder . "/" . $sFileName ,'RenameFile');
$sNewDir = ServerMapFolder( $resourceType, $currentFolder . "/" . $sNewName ,'RenameFile');

    /*if(empty($_COOKIE[xxxxxx])) {
    $sErrorNumber   = "501";
}else */if( empty($_GET['FileName']) or empty($_GET['NewName']) ) {
  $sErrorNumber  = "502";
}else  if(!is_file($sServerDir)) {
  $sErrorNumber = '503';
  $sErrorMsg    = $sFileName .' is not a file';
}else if(!file_exists($sServerDir)) {
  $sErrorNumber = '504';
  $sErrorMsg    = $sFileName .' is not exists';
}else{
  if(rename($sServerDir,$sNewDir)) {
     $sErrorNumber    = "0";
  }else{
     $sErrorNumber    = "555";
     $sErrorMsg = "无法重命名此文件:".$sServerDir;
  }
}
echo '<Error number="' . $sErrorNumber . '"  originalDescription="' . ConvertToXmlAttribute( $sErrorMsg ) . '" />';
}
修改function GetFoldersAndFiles( $resourceType, $currentFolder )函数,并添加以下内容:
复制内容到剪贴板代码:
$agent = $_SERVER['HTTP_USER_AGENT'];
if(stripos($agent,"gecko")>0) {
  $currentFolder   = urldecode($currentFolder);
}
if(stripos($agent,"gecko")>0) {
  $sServerDir = iconv("utf-8","gbk",$sServerDir);
}
5。第五步 \fckeditor\editor\filemanager\connectors\php\config.php
第28行修改为:$Config['ConfigAllowedCommands'] = array('QuickUpload', 'FileUpload', 'GetFolders', 'GetFoldersAndFiles', 'CreateFolder','DeleteFolder','DeleteFile','RenameFolder','RenameFile') ;

6。第六步 \fckeditor\editor\filemanager\connectors\php\connector.php
在相应地方添加以下代码:
复制内容到剪贴板代码:
  case "DeleteFolder":
   DeleteFolder( $sResourceType, $sCurrentFolder );
   break ;
  case "DeleteFile":
   DeleteFile( $sResourceType, $sCurrentFolder );
   break ;
  case "RenameFolder":
   RenameFolder( $sResourceType, $sCurrentFolder );
   break ;
  case "RenameFile":
   RenameFile( $sResourceType, $sCurrentFolder );
   break ;
7。第七步 \fckeditor\editor\filemanager\connectors\php\io.php
第70行函数function CreateServerFolder( $folderPath, $lastFolder = null )里添加:

$folderPath = iconv("utf-8","gbk",$folderPath);


8。第八步 \fckeditor\editor\filemanager\connectors\php\util.php
第50行修改为:
return (mb_convert_encoding(htmlspecialchars($value),"UTF-8","GBK")) ;

上面的为完全版,但要自己动手。在 http://www.uushare.com/user/littlenew/file/1942702里有免费版,不过里面某些代码已经加密,请勿破解,保证不含任何恶意代码,也不会有反向连接等一系列其它联网活动。

[url= http://www.hazytime.cn/article/article.asp?/6370-1-1.html]也可以到我的网站查看[/url]。

1。我的IE8在apache下不能浏览中文目录里的图片,怎么办?
       在IE8的设置里选中:发送 UTF-8 URL

2。免费版本已经存在的问题:在firefox不能修改、删除文件,只能上传文件.

测试环境:windows 2003 + apache 2.2.11 + PHP5.3 + UTF-8(不带BOM)


视频教程列表
文章教程搜索
 
Access数据库推荐教程
Access数据库热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058