给fckeditor添加查看、修改、删除文件功能[php][迷茫时代原创]

2009年8月25日 由于PHP存在中文目录读取问题,将延期发布。

2009年9月3日 正式发布:查看、修改、删除文件功能的fckeditor 2.6.4.1
相关图片请查看:http://home.blueidea.com/attachment/200909/1/336696_1251813604S01b.gif
相关其它:http://home.blueidea.com/apps.php?do=case&ac=lists&uid=336696&picid=39979&oid=0

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")) ;


此版本为PHP版本,可以查看中文目录文件,也可以修改中文目录,但最好是简体中文。创建文件夹时要注意,此版本可以创建特殊文件夹,但不能浏览、修改、删除。由于此版本含有“删除”功能,使用者请打开权限设置。
文章中含有/*的内容为选项,可以自行打开,含有//的为注释。


至此,所有文件修改完毕。马上体验查看/重命名/删除上传多余文件的功能吧!!!!!!

本文以本站fckeditor_2.4.1(asp)为蓝板,精心制作而成。不存在抄袭。如有雷同,实属巧合。

此文为本站原创,如需转载,请与管理员联系。

[如果需要定制fckeditor的话,可联系:页底邮箱(注明:fckeditor)

300*300
  • 没有相关文章
  • 没有评论
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.00521 秒