By default the fckeditor file browser that comes with it doesn't allow file deleting or folder deleting because of the security risk. Its a bit of a pain but it is possible to get the file browser to delete files. Here is how I went about it for php:
edit "editor/filemanager/connectors/php/commands.php" and add:
-
function DeleteFile( $resourceType, $currentFolder ) {
-
$file = $_SERVER['DOCUMENT_ROOT'].$_GET['FileUrl'];
-
} else {
-
echo '<error number="1" originaldescription="unable to locate file">' ;
-
}
-
}
-
function DeleteFolder( $resourceType, $currentFolder ) {
-
$folder = $_SERVER['DOCUMENT_ROOT'].$_GET['FolderName'];
-
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($file!="." && $file!="..") {
-
} else {
-
DELETE_RECURSIVE_DIRS($dirname."/".$file);
-
}
-
}
-
}
-
}
modify editor/filemanager/connectors/php/connector.php so that the command switch looks like this:
-
switch ( $sCommand ) {
-
case 'GetFolders' :
-
GetFolders( $sResourceType, $sCurrentFolder ) ;
-
break ;
-
case 'GetFoldersAndFiles' :
-
GetFoldersAndFiles( $sResourceType, $sCurrentFolder ) ;
-
break ;
-
case 'CreateFolder' :
-
CreateFolder( $sResourceType, $sCurrentFolder ) ;
-
break ;
-
/******ADDED DELETE COMMANDS******/
-
case 'DeleteFile' :
-
DeleteFile( $sResourceType, $sCurrentFolder ) ;
-
break ;
-
case 'DeleteFolder' :
-
DeleteFolder( $sResourceType, $sCurrentFolder ) ;
-
break ;
-
}
modify editor/filemanager/connectors/php/config.php allowed commands:
-
$Config['ConfigAllowedCommands'] = array('QuickUpload', 'FileUpload', 'GetFolders', 'GetFoldersAndFiles', 'CreateFolder', 'DeleteFile', 'DeleteFolder') ;
You will also need to make sure that this connector is enabled in this file also but you knew that already didn't you?
-
$Config['Enabled'] = true ;
modify editor/filemanager/browser/default/frmresourceslist.html.html so that the functions look like this:
-
oListManager.GetFolderRowHtml = function( folderName, folderPath, folderUrl ) //added folderUrl
-
{
-
// Build the link to view the folder.
-
var sLink = '<a href="#" onclick="OpenFolder(\'' + folderPath.replace( /'/g, '\\\'') + '\');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"> ' +
-
sLink +
-
folderName +
-
'</a>' +
-
'</td><td align="right"><a href="#" onclick="DeleteFolder(\''+folderName+'\',\''+ folderUrl.replace( /'/g, '\\\'') + '\');return false;">DELETE</a></td></tr>' ;
-
}
-
-
{
-
// Build the link to view the folder.
-
var sLink = '<a href="#" onclick="OpenFile(\'' + fileUrl.replace( /'/g, '\\\'') + '\');return false;">' ;
-
-
// Get the file icon.
-
var sIcon = oIcons.GetIcon( fileName ) ;
-
-
return '<tr>' +
-
'<td width="16">' +
-
sLink +
-
'<img src="'+fileUrl+'" border="0" style="border:1px solid black; margin:5px;" alt="" height="70" /></a>' +
-
'</td><td> ' +
-
sLink +
-
fileName +
-
'</a>' +
-
'</td><td align="right" nowrap> ' +
-
fileSize +
-
' KB' +
-
'</td><td align="right"><a href="#" onclick="DeleteFile(\''+fileName+'\',\'' + fileUrl.replace( /'/g, '\\\'') + '\');return false;">DELETE</a></td></tr>' ;
-
}
-
-
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 ) ;
-
}
-
}
*NOTE* This will also show a thumbnail image - you can change the function to turn this off if you want *NOTE*
oh and also in the function modify this..
-
oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/" ) ) ;
to be this...
-
oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/", sCurrentFolderUrl ) ) ;
I think that is all.. if I missed anything let me know and I will update this quide.
I was led here by search for flex file manager through Google. It led me to a Flex file manager that I think is really cool how can I get the source code? I need to build the same thing. I currently use the asfusion file explorer but it has issues I cannot resolve for some users. So I need to make it like flex and I see its already been done. Can you help me?
George Smith
oh, so great. Thank you so much
Could this ‘patch’ be posted as a download
LoC
yeah, but then I would need to update the download with new releases of fck
What about a full download
Or.. which version are we talking about? Might be that I am trying to fix it in the wrong version (latest.. uuhhmm 2.5.1 or something like that. But tne again, wehere would i dl an older version…
pretty annoying that i cant delete files with fck.
LoC
This should work with the latest version unless I missed something. I’m fairly certain I documented all of my steps. Are you stuck?
Nice solution Marc,
I works fine in version 2.5
Version 2.5.1 (latest); it gives a js error in firefox (not tested other browsers)
> folderUrl is not defined
http://EXAMPLE.COM/js/fckeditor/editor/filemanager/browser/default/frmresourceslist.html
Line 58
Also I found a little bug in your code for commands.php
Your code:
—–
function DELETE_RECURSIVE_DIRS($dirname) { // recursive function to delete
// all subdirectories and contents:
if(is_dir($dirname))$dir_handle=opendir($dirname);
—–
if(is_dir($dirname))$dir_handle=opendir($dirname);
—–
should read:
if(is_dir($dirname)){
$dir_handle=opendir($dirname);
Thanks a lot ! Very usefull
Two little things :
-In the “editor/filemanager/connectors/php/commands.php” file you show, i think a “{” has been lost on line 19 (function DELETE_RECURSIVE_DIRS).
-In the same file, the && need to be decoded on line 21.
Thanks Seb, I’ve fixed up those errors.
Thanks! This is just what I was looking for. I made some additional changes to avoid an error when creating a new folder. In frmresourceslist.html add to the top of oListManager.GetFolderRowHtml
// when a folder is created
if (folderUrl == null) {
folderUrl = ”;
}
And to use thumbnails in Image mode and icons in all other modes, edit frmresourceslist.html and before ‘return’ of oListManager.GetFileRowHtml add:
var thumbnail = ‘images/icons/’ + sIcon + ‘.gif’;
var height = 16;
if (oConnector.ResourceType == ‘Image’) {
thumbnail = fileUrl;
height = 70;
}
and make the ‘ +
The end of my comment should read like this (replace { and } with a tag angles):
and make the {img line of the return statement be:
‘{img src=”‘+thumbnail+’” border=”0″ alt=”" height=”‘ + height + ‘” /}{/a}’ +
Fixed… no idea what went wrong initialy.. guess I needed that short leave to clear the mind.
Doing some additions and changes to the code.. if ur intrested email me.
LoC
You are great Dude… I love this addon… Keep up the good work!!
Hello from Japan.
Thanks for nice scripts.
>Mr.Dave
I modified look like this.
var thumbnail = ‘images/icons/’ + sIcon + ‘.gif’;
var height = 16;
if (sIcon == ‘jpg’ || sIcon == ‘gif’ || sIcon == ‘png’ || sIcon == ‘bmp’) {
thumbnail = fileUrl;
height = 70;
}
and I modified deleteFile&Folder function,
global $Config ;
$file = $Config[’UserFilesAbsolutePath’]…..
if “$_SERVER[’DOCUMENT_ROOT’]”,I can delete other files.
great thanx!
Hi Marc! Nice job you’ve done. But it didn’t actually delete my files or folders because $_SERVER[’DOCUMENT_ROOT’].$_GET[’FileUrl’] wasn’t the place where my files were located so I took idea from Fukumen Rider
and modified your code like this:
in the view i just pass file/folder - names:
[code]
function DeleteFile( fileName )
{
if (confirm(’Are you sure you wish to delete ‘ + fileName + ‘?’)) {
oConnector.SendCommand( ‘DeleteFile’, “FileName=” + escape( fileName ), Refresh ) ;
}
}
[/code]
in commands.php
[code]
function DeleteFile( $resourceType, $currentFolder ) {
global $Config ;
$file = $Config[’UserFilesAbsolutePath’].strtoupper($resourceType[0]).substr($resourceType,1).’/’.$_GET[’FileName’];
if (is_file($file)) {
unlink($file);
} else {
echo ” ;
}
}
[/code]
Great patch, I think you should post it to FCK dev team here:
http://dev.fckeditor.net/ticket/354
cause it should be included in the default distribution