首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

[原创]让FCKeditor的File manager支持”删除” (php),该怎么处理

2012-03-29 
[原创]让FCKeditor的File manager支持”删除” (php)FCKeditor是一款很好用的所见即所得编辑器, 内置的File

[原创]让FCKeditor的File manager支持”删除” (php)
FCKeditor是一款很好用的所见即所得编辑器, 内置的File manager也实现了基本的文件管理功能, 唯一遗憾的是, 不支持删除…

没关系, 其实只需以下几步就可以实现删除文件和文件夹:

1, fckeditor\editor\filemanager\browser\default\frmresourceslist.html, 编辑:

PHP code
oListManager.GetFolderRowHtml = function( folderName, folderPath, folderUrl ){// Build the link to view the folder.var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath( folderPath ) + '\');return false;">' ;return '<tr>' +'<td width="16">' +sLink +'<img alt="" src="images/Folder.gif" width="16" height="16" border="0"><\/a>' +'<\/td><td nowrap colspan="2">&nbsp;' +sLink +folderName +'<\/a>' +'<\/td><td align="right" width="45">- <a href="#" onclick="DeleteFolder(\''+folderName+'\',\''+ folderUrl.replace( /'/g, '\\\'') + '\');return false;">Delete</a></td><\/tr>' ;}

2, fckeditor\editor\filemanager\browser\default\frmresourceslist.html, 编辑:
PHP code
oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize ){// Build the link to view the folder.var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;">' ;// Get the file icon.var sIcon = oIcons.GetIcon( fileName ) ;return '<tr>' +'<td width="16">' +sLink +'<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' +'<\/td><td>&nbsp;' +sLink +fileName +'<\/a>' +'<\/td><td align="right" nowrap>&nbsp;' +fileSize +' KB' +'<\/td><td align="right" width="45">- <a href="#" onclick="DeleteFile(\''+fileName+'\',\'' + fileUrl.replace( /'/g, '\\\'') + '\');return false;">Delete</a></td><\/tr>' ;}

3, fckeditor\editor\filemanager\browser\default\frmresourceslist.html, 增加:
PHP code
function DeleteFile( fileName, fileUrl ){if (confirm('Are you sure you wish to delete ' + fileName + '?')) {oConnector.SendCommand( 'DeleteFile', "FileUrl=" + escape( fileUrl ), Refresh ) ;}}function DeleteFolder( folderName, folderPath ){if (confirm('Are you sure you wish to delete \'' + folderName + '\' and all files in it?')) {oConnector.SendCommand( 'DeleteFolder', "FolderName=" + escape( folderPath + folderName ), Refresh ) ;}}

4, fckeditor\editor\filemanager\browser\default\frmresourceslist.html, 编辑:
PHP code
oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/", sCurrentFolderUrl ) ) ;

 

5, fckeditor\editor\filemanager\connectors\php\commands.php, 添加:
PHP code
function DeleteFile( $resourceType, $currentFolder ) {$file = $_SERVER['DOCUMENT_ROOT'].$_GET['FileUrl'];if (is_file($file)) {unlink($file);} else {echo '<error number="1? originaldescription=”unable to locate file">';}}function DeleteFolder( $resourceType, $currentFolder ) {$folder = $_SERVER['DOCUMENT_ROOT'].$_GET['FolderName'];if (is_dir($folder) ) {DELETE_RECURSIVE_DIRS($folder);} else {echo '<error number="2? originaldescription="unable to locate folder">';}}function DELETE_RECURSIVE_DIRS($dirname) { // recursive function to delete// all subdirectories and contents:if(is_dir($dirname))$dir_handle=opendir($dirname);while($file=readdir($dir_handle)) {if($file!="." && $file!="..") {if(!is_dir($dirname."/".$file)) {unlink ($dirname."/".$file);} else {DELETE_RECURSIVE_DIRS($dirname."/".$file);}}}closedir($dir_handle);rmdir($dirname);} 


6, fckeditor\editor\filemanager\connectors\php\connector.php, 编辑:
PHP code
// Execute the required command.switch ( $sCommand ){case 'GetFolders' :GetFolders( $sResourceType, $sCurrentFolder ) ;break ;case 'GetFoldersAndFiles' :GetFoldersAndFiles( $sResourceType, $sCurrentFolder ) ;break ;case 'CreateFolder' :CreateFolder( $sResourceType, $sCurrentFolder ) ;break ;case 'DeleteFile':DeleteFile( $sResourceType, $sCurrentFolder ) ;break ;case 'DeleteFolder':DeleteFolder( $sResourceType, $sCurrentFolder ) ;break ;}

7, fckeditor\editor\filemanager\connectors\php\config.php, 编辑:
PHP code
$Config['ConfigAllowedCommands'] = array('QuickUpload', 'FileUpload', 'GetFolders', 'GetFoldersAndFiles', 'CreateFolder', 'DeleteFile', 'DeleteFolder') ;

8, Enjoy~

[解决办法]
用户可删除服务器上的文件?

不是他不提供,而是不敢提供
[解决办法]
ding

热点排行