A Small History
CKEditor has been one of the most popular and used WYSIWYG editor for web, which has been used by many popular open source projects, websites and companies. According to its official website, FCKeditor has been around for more than six years. Since 2003 it has built a strong user community becoming the most used editor in the market, accumulating more than 3,5 million downloads. On 2009, the company decided renaming the editor, bringing to the light their next generation solution: CKEditor 3.0.
CKEditor inherits the quality and strong features people were used to find in FCKeditor, in a much more modern product, added by dozens of new benefits, like accessibility and ultimate performance.CKEditor has made many features pluggable so that it can be extended by developers according to their needs.
Why this tutorial?
However, the new CKEditor does not provide the File Manager/File Browser that it used to provide by default in FCKEditor. This functionality is now provided by CKFinder. CKFinder provides many cool functions and is definitely a better product than traditional FCKEditor’s FIle Browser, but its not a free product and users have to purchase the license in order to use the product.
If you are not willing to purchase CKFinder you can make your own external file manager and plugin to CKEditor through its APIs, alternatively you can directly integrate the FCKEditor’s File Manager (File Browser) feature with CKEditor. This is what i am going to describe in this short tutorial.
Before starting the tutorial you may also like to view the fully functional demo, or you may download the example and start working on it. Please note that this tutorial is for the PHP language and connectors, but same steps can also be applied for other supported languages and connectors.
Also I assume that you have sufficient knowledge about integrating CKEditor on your page.
Starting with the tutorial
Download the CKEditor and copy it to your desired folder. In this example I have copied it to
siteroot/filemanager_in_ckeditor/js/ckeditor
demo.html is the page where I would like to add the WYSIWYG editor, and I have placed my page over here:
siteroot/filemanager_in_ckeditor/demo.html
Since we are going to integrate the inbuilt File Manager available in FCKEditor we will copy the ‘filemanager’ folder from the FCKEditor source files which is genereally located in
fckeditor/editor/
In this example I have copied the ‘filemanager’ folder to
siteroot/filemanager_in_ckeditor/js/ckeditor/
At this stage you may delete the connectors from the filemanager folder which you are not using. I have deleted all the connector folders except the ‘php’ connector which I am using in this example.
Once the required files are copied you need to tie up the filemanager with CKEditor and make it active in the code. To do this you need to modify the CKEditor intialization code like below. (Obviously this goes in demo.html page in my case)
CKEDITOR.replace( 'editor1', { filebrowserBrowseUrl :'js/ckeditor/filemanager/browser/default/browser.html?Connector=http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/connector.php', filebrowserImageBrowseUrl : 'js/ckeditor/filemanager/browser/default/browser.html?Type=Image&Connector=http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/connector.php', filebrowserFlashBrowseUrl :'js/ckeditor/filemanager/browser/default/browser.html?Type=Flash&Connector=http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/connector.php'} );
The above options, enables the “Browse Server” buttons on the “Link”, “Image”, “Flash” dialogs. You will have to adjust the above paths according to your directory structure. Also please note that for the sake of simplicity I have hard coded my website domain (www.mixedwaves.com) in the above paths, this should be changed to whatever is applicable in your case and can be added dynamically instead of hard coding it.
One important thing to remember at this stage is that while integrating the File Browser in CKEditor we still have to make configuration changes that we used to do for enabling the Browse and Upload functions in FCKEditor. Like enabling the php connector and specifying the UserFilesPath to correct location in:
filemanager/connectors/php/config.php
Up to now if everything has gone correct, you should be able to see the “Browse Server” buttons in the “Link”, “Image” and “Flash” dialogs. Clicking on the “Browse Server” button would open the “File Manager” window.
As a last step to making everything work you need to modify the following file:
filemanager/browser/default/frmresourcelist.html
You need to add the following JavaScript function, where all the other Javascript functions have been defined. Copy and paste the below code:
function GetUrlParam( paramName ) { var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ; var oMatch = oRegex.exec( window.top.location.search ) ; if ( oMatch && oMatch.length > 1 ) return decodeURIComponent( oMatch[1] ) ; else return '' ; }
In the same file you need to modify the function called “OpenFile”. Search the function “OpenFile” and replace it with the following function:
Update: 25 June 2011
File names with spaces are now visible in preview window. Earlier filenames with spaces were not encoded correctly hence were not visible in preview window. Thanks to Angela Yamat and Len
function OpenFile( fileUrl ) { //PATCH: Using CKEditors API we set the file in preview window. funcNum = GetUrlParam('CKEditorFuncNum') ; //fixed the issue: images are not displayed in preview window when filename contain spaces due encodeURI encoding already encoded fileUrl window.top.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl); /////////////////////////////////// window.top.close() ; window.top.opener.focus() ; }
The above code essentially sets the file URL to the preview window in the dialog box, when user selects a file in the File Manager.
With this you are done integrating the File Manager in CKEditor.
If everything has been configured and patched correctly, you should now be able to use a fully functional File Browser window just like you used to do in old FCKEditor.
Update: 3rd April 2010
With the generous effort of Brombomb, you can now also enable the ‘Upload’ tab for quick upload of files in your File Browser. You can find the hack on this link: http://stackoverflow.com/questions/1903510/ckeditor-integration-with-fckeditor-filebrowser/2564039
I have also implemented the above solution but with few modifications and in more systematic way so that the functionality is as close as possible with the old FCKEditor file browser. Thanks again to Brombomb.
Continuing with the tutorial, Enabling Quick Upload
Once you are done with the above steps you will have fairly working File Browser Window. However the old FCKEditor also supported a feature called Quick Upload and had separate upload tab. The upload tab can be enabled and made functional by following the below four steps.
In your CKEditor initialization code you need to add few more config variables as shown below that enables the Quick Upload tab. (Again this goes in demo.html page)
CKEDITOR.replace( 'editor1', { filebrowserBrowseUrl :'js/ckeditor/filemanager/browser/default/browser.html?Connector=http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/connector.php', filebrowserImageBrowseUrl : 'js/ckeditor/filemanager/browser/default/browser.html?Type=Image&Connector=http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/connector.php', filebrowserFlashBrowseUrl :'js/ckeditor/filemanager/browser/default/browser.html?Type=Flash&Connector=http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/connector.php', filebrowserUploadUrl :'http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/upload.php?Type=File', filebrowserImageUploadUrl : 'http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/upload.php?Type=Image', filebrowserFlashUploadUrl : 'http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/upload.php?Type=Flash' });
Again need not mention, that the domain needs to be replaced by your own domain. The last three config variables in the above code enables the “Upload” tab in your “Flash”, “Image”, “File” dialogs. Same can be done for “Media” type which I haven’t done in this tutorial.
Now in next few steps we are going to modify/hack few files, this needs little care and attention.
Open the the file
filemanager/connectors/php/upload.php
And search and replace the PHP function call “FileUpload” with the following code snippet
// Get the CKEditor Callback $CKEcallback = $_GET['CKEditorFuncNum']; //pass it on to file upload function FileUpload( $sType, $sCurrentFolder, $sCommand, $CKEcallback );
Now open the below file and search for the function definition “FileUpload”.
filemanager/connectors/php/commands.php
Here we are going to add a new parameter to the function parameter list, as well as some modification in the body of the function. I would recommend you to replace the entire function definition with the following new function definition
// Notice the last paramter added to pass the CKEditor callback function function FileUpload( $resourceType, $currentFolder, $sCommand, $CKEcallback = '' ) { if (!isset($_FILES)) { global $_FILES; } $sErrorNumber = '0' ; $sFileName = '' ; //PATCH to detect a quick file upload. if (( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) ) || (isset( $_FILES['upload'] ) && !is_null( $_FILES['upload']['tmp_name'] ) )) { global $Config ; //PATCH to detect a quick file upload. $oFile = isset($_FILES['NewFile']) ? $_FILES['NewFile'] : $_FILES['upload']; // Map the virtual path to the local server path. $sServerDir = ServerMapFolder( $resourceType, $currentFolder, $sCommand ) ; // Get the uploaded file name. $sFileName = $oFile['name'] ; $sFileName = SanitizeFileName( $sFileName ) ; $sOriginalFileName = $sFileName ; // Get the extension. $sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ; $sExtension = strtolower( $sExtension ) ; if ( isset( $Config['SecureImageUploads'] ) ) { if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false ) { $sErrorNumber = '202' ; } } if ( isset( $Config['HtmlExtensions'] ) ) { if ( !IsHtmlExtension( $sExtension, $Config['HtmlExtensions'] ) && ( $detectHtml = DetectHtml( $oFile['tmp_name'] ) ) === true ) { $sErrorNumber = '202' ; } } // Check if it is an allowed extension. if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) ) { $iCounter = 0 ; while ( true ) { $sFilePath = $sServerDir . $sFileName ; if ( is_file( $sFilePath ) ) { $iCounter++ ; $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ; $sErrorNumber = '201' ; } else { move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ; if ( is_file( $sFilePath ) ) { if ( isset( $Config['ChmodOnUpload'] ) && !$Config['ChmodOnUpload'] ) { break ; } $permissions = 0777; if ( isset( $Config['ChmodOnUpload'] ) && $Config['ChmodOnUpload'] ) { $permissions = $Config['ChmodOnUpload'] ; } $oldumask = umask(0) ; chmod( $sFilePath, $permissions ) ; umask( $oldumask ) ; } break ; } } if ( file_exists( $sFilePath ) ) { //previous checks failed, try once again if ( isset( $isImageValid ) && $isImageValid === -1 && IsImageValid( $sFilePath, $sExtension ) === false ) { @unlink( $sFilePath ) ; $sErrorNumber = '202' ; } else if ( isset( $detectHtml ) && $detectHtml === -1 && DetectHtml( $sFilePath ) === true ) { @unlink( $sFilePath ) ; $sErrorNumber = '202' ; } } } else $sErrorNumber = '202' ; } else $sErrorNumber = '202' ; $sFileUrl = CombinePaths( GetResourceTypePath( $resourceType, $sCommand ) , $currentFolder ) ; $sFileUrl = CombinePaths( $sFileUrl, $sFileName ) ; if($CKEcallback == '') { SendUploadResults( $sErrorNumber, $sFileUrl, $sFileName ) ; } else { //issue the CKEditor Callback SendCKEditorResults ($sErrorNumber, $CKEcallback, $sFileUrl, $sFileName); } exit ; }
As a final step, we are going to modify the below file and add a new function towards the end of the file
filemanager/connectors/php/io.php
Add the below function towards the end of the file
// This is the function that sends the results of the uploading process to CKEditor. function SendCKEditorResults ($errorNumber, $CKECallback, $fileUrl, $fileName, $customMsg ='') { // Minified version of the document.domain automatic fix script (#1919). // The original script can be found at _dev/domain_fix_template.js echo <<<EOF <script type="text/javascript"> (function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})(); EOF; if ($errorNumber && $errorNumber != 201) { $fileUrl = ""; $fileName= ""; } $msg = ""; switch ($errorNumber ) { case 0 : $msg = "Upload successful"; break; case 1 : // Custom error. $msg = $customMsg; break ; case 201 : $msg = 'A file with the same name is already available. The uploaded file has been renamed to "' . $fileName . '"' ; break ; case 202 : $msg = 'Invalid file' ; break ; default : $msg = 'Error on file upload. Error number: ' + $errorNumber ; break ; } $rpl = array( '\\' => '\\\\', '"' => '\\"' ) ; echo 'window.parent.CKEDITOR.tools.callFunction("'. $CKECallback. '","'. strtr($fileUrl, $rpl). '", "'. strtr( $msg, $rpl). '");' ; echo '</script>'; }
The above function essentially sends back the result of the upload to the preview window. It will alert if something wrong has happened like uploaded an invalid file.
With this we are done with integrating a full featured File Browser in CKEditor.
I hope this tutorial is useful to you. Please post your doubts or questions you may have and I would be happy to respond to it.
PS. I have taken utmost care to place the above code snippets correctly, however my WYSIWYG editor seems to change the PHP and JS code undesirably. If you find any errors/typos in the above code snippets you can check the actual source code files; it would be really great if you can bring it to my notice so that I can correct it and also help you out if possible.
it works
thanks
could u please post it for aspx language?? i will be very thankh ful to u
Please put it for aspx language also
i’ll be very tahnkful to u
Great! Thanks for the post.
Just one thing, the preview doesn’t work when I browse an image with space in the filename.
Oh, preview is now working properly, I just update the file ‘frmresourceslist/html’ at line110 with this one;
window.top.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl );
Basically, I just load the fileUrl directly without encoding it. Will that be an issue?
Unfortunately I am not an aspx guy so I can’t do it right now, however the main purpose for writing the tutorial was that anyone can port it to any language if the understand the tutorial.
Hi Angela, this is a known issue reported by Len http://www.mixedwaves.com/2010/02/integrating-fckeditor-filemanager-in-ckeditor/comment-page-3/#comment-2627
I need to fix that. I am not sure if removing encoding works well, but you need to test it rigorously with different file names.
To all readers I have recently updated the file manager code which fixes a bug related to file names with spaces. Earlier the filenames with spaces were not visible in the preview window, but displayed correctly in editor window. This was due do incorrect encoding of fileUrl which was already encoded creating invalid filenames. The problem is fixed now and should work well with filenames having spaces. Thanks to Angela Yamat who implemented similar fix and bringing this to notice. Thanks to Len for reporting this problem earlier.
Please post if you find any such bugs (and possible solutions) so that we can make a better code.
Hi,
I was wondering if there is a way to have separate folders (based on my client) to use for uploads of images.
Thanks, Rick
Hi Rick,
It is possible to have separate folders for eg. separate folder structure for each user instead of common one. Although it requires some extra bit of coding. The hack is to dynamically generate the userfiles path which we otherwise hardcode in the config.php
Inside your connectors/php/config.php you can see the variable set as:
// Path to user files relative to the document root.
$Config['UserFilesPath'] = ‘/userfiles/’ ;
You can set to something else like
// Path to user files relative to the document root.
$Config['UserFilesPath'] = ‘/userfiles/XXXX/’ ;
Where XXXX can be a value from user’s Session variable like user id etc.
Since its all server side code you can easily access the already existing session created by your main app.
hi Penuel, I am new to CKeditor and I had never used FCKeditor, so this tutorial is a great help to you, thank you. In terms of your /userfiles/XXXX/ suggestion above, it’s understandable but my member site is a little different and I want to see if you are able to suggest something for my scenario.
For example, if all users upload files to the same folders such as image to imageFile folder, pdf to pdfFile folder, words file to wordFile folder, how would this be done?
/whatever/imageFile/
–userAimagefile.jpg
–userBimagefile.jpg
–userCimagefile.jpg
/whatever/pdfFile/
–userApdffile.jpg
–userBpdffile.jpg
–userCpdffile.jpg
/whatever/wordFile/
–userAwordfile.jpg
–userBwordfile.jpg
–userCwordfile.jpg
Thanks in advance.
@100D it would require you to edit/hack multiple files and can be bit complex for some one new to this. The exact steps would be difficult to explain here, but a similar function is available already in FCKeditor where Fckeditor categorizes files in different folders based on their type. For eg. image files in image folder, flash files in flash folder, video files like avi etc to media folder, other formats like txt, word to Files folder. you can switch between folders by selecting the resource type drop down in left sidebar of the file browser. not all resource types are available in the filebrowser everytime, but when you try to edit a ‘link’ you can see all the resource types and switch between them. Looking at this, you have the possibility of extending the current functionality to what you require with some reverse engineering and hacking.
Thanks for that, I will look into this once I get the part you explained working.
I have gotten most working except for when I try to select a file from the browser, it doesn’t do anything. Firebug detected that as an error and the error is “Permission denied to access property ‘CKEDITOR’”. When I digged in and it appears that the OpenFile function in frmresourceslist.html file, where the line says window.top.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl); is the problem, do you know or has anyone gotten the same issue previously?
I am thinking it has something to do with my userpath but then if I was able to upload file and browse, it shouldn’t be a problem?
Once I figure this part out, I am good to move on and expose deeper.
thanks for this hack by the way.
I believe its problem similar to http://www.mixedwaves.com/2010/02/integrating-fckeditor-filemanager-in-ckeditor/comment-page-3/#comment-2638, you may try to fix it by what i said below it; could be due to different domains (even urls with or without www) and Javascript is denying the access to objects in other domain.
Thanks Penuel. I fixed the problem. The problem was caused simply due to domain issue. I had the files in the main domain where trying to access these files from the subdomain. Symbolic link fixed it. Now I am moving on to see the user access issue I am having.
Hi Penuel,
I hope today finds you well!
I have a question regarding ckfinder settings for image folders. I have gotten the sub directories working: “\images\40″ “\images\50″ for example. In the finder I need to pass the js the customer id (40, 50) as example so that the client only can access their image folder. I think this could be done but I don’t know where the js for the finder resides. Hoping that you can help!
Thanks, Rick…
Hi Penuel,
I hope today finds you well!
I have a question regarding ckfinder settings for image folders. I have gotten the sub directories working: \images\40 \images\50 for example. In the finder I need to pass the js the customer id (40, 50) as example so that the client only can access their image folder. I think this could be done but I don’t know where the js for the finder resides. Hoping that you can help!
Thanks, Rick…
Great! Thanks for the post.
Thanks penuel
It is very helpful to me…
Great Tutorial it worked perfectly at my localhost but when i move it to my production are then it start giving me the error “he server didnot reply with proper xml data please check ur configurations”
Any help would be appreciated
Its generally related to urls you set in CKEditor initialization code (i have hard coded it on above code). Make sure your urls are correct. Also please make sure the userfilepath in config.php has correct value.
Hi Penuel,
Great tutorial.
Only got one question. Can please explain what changes are to be made in the ‘config.php’ file.. I’m not familiar with php and were in a lost there (is it possible to make those changes in the ‘config.aspx’??)
many thanks,
Avi
Config.php is only about updating the userfilepath variable to a directory location where files get uploaded. Its pretty easy for anyone to understand so feel free to open and look at it.
Thanks for the quick reply, but I did everything (I’ve checked several times) and when I hit ‘Browse Server’, the file manager window gets open, but I get error message saying that the server didn’t reply with a proper xml data.. and when I try uploading a file, it’s just dosen’t work..
Any thoughts?
Please make sure you don’t have a cross domain. A problem can arise when there are two different urls loaded in the main window and the file browser window. For eg. the main window where you see the editor has http://yourdomain.com and the browser popup has same url but with extra www (www.yourdomain.com). This is cross domain and it will throw an error. Please check if that has been an issue, this has been faced by mean readers.
I’m running the site in localhost, can it be the it changes the url?
How can I solve it?
Plus, I thought it was a permission issue, but I’ve checked and I’ve got full control with the library.
Hi Penuel!
thanks for sharing your work.
Please help with the following:
(i changed $Config['UserFilesPath'] = ‘../../../userfiles/’ ; in config.php)
browsing the server and uploading works correctly.
when it comes to insert the image, the wrong url is displayed.
when removing ‘../../../’ its ok.
wrong
right
can this be corrected in : frmresourceslist.html ?
thanks for helping.
Till.
hi theks allot for coding
i did everthing as told but when i open the “Browse Server” i get this error what is it?
Error creating folder “/var/www/vhosts/MYWEBSITE.COM/httpdocs” (mkdir() [function.mkdir]: SAFE MODE Restriction in effect. The script whose uid is 10057 is not allowed to access /var owned by uid 0)
this is the first time i get this caind of error.
pls help me?!
Idan its due to safemode on on your server http://php.net/manual/en/features.safe-mode.php
@Till, I haven’t tried that but I would suggest can’t we have a path from the root of the server? Alternative the config.php has a another variable for absolute path $Config['UserFilesAbsolutePath'] you may also try that.
Hi Penuel,
Thank you SO much for this solution!! I tried 2 other free solutions that failed, and finding this was just awesome! What a great idea to just grab the free solution that was already in the old fckeditor and use it for the new one! Again, MANY thanks!!
One thing I noticed with the code is that when you upload a file through the ‘Upload’ tab that appears on the main file insert window (not the ‘Upload’ form that appears when you click ‘Browse Server’, but the link that displays along the top when you first click the ‘Insert Image’ or ‘Flash’ button on the WYSIWYG editor) does not upload the file to the correct directory. For example, if I click the ‘Image’ button, and then click the ‘Upload’ tab at the top, I want the file to upload to my ‘/userfiles/image/’ directory, but instead it uploads to just the ‘/userfiles/’ directory.
The problem lies in this file: filemanager/connectors/php/upload.php at around line 43-46, where it says:
// The file type (from the QueryString, by default ‘File’).
$sType = isset( $_GET['Type'] ) ? $_GET['Type'] : ‘File’ ;
$sCurrentFolder = “/” ;
That $sCurrentFolder directory shouldn’t always get set to “/”, but should get set appropriately based on the file type. Since there are only 2 options (Image or Flash), and the directories that get auto-created in your ‘userfiles’ directory are ‘image’ and ‘flash’, I hard-coded some “if” statements to fix this. Replace the above code with:
// The file type (from the QueryString, by default ‘File’).
//$sType = isset( $_GET['Type'] ) ? $_GET['Type'] : ‘File’ ;
//$sCurrentFolder = “/” ;
// EDIT: regardless of the file type, the current folder would default to the root directory.
// to fix, we’ll add an if statement to check for the file type. if one is found, it
// will either be ‘image’ or ‘flash’ since those are the only 2 options, so we’ll set
// the current folder to one of those explicitly.
if (isset($_GET['Type'])) {
$sType = $_GET['Type'];
if ($_GET['Type'] == ‘Image’) {
$sCurrentFolder = “image/”;
} else {
$sCurrentFolder = “flash/”;
}
} else {
$sType = ‘File’;
$sCurrentFolder = “/”;
}
Now that ‘Upload’ tab works like it should, along with the ‘Upload’ form when you click ‘Browse Server’.
Hi Justin, Thanks for your feedback and reporting a possible problem. However I tested it on my local machine and it works as expected without the changes you told. The files are uploaded to correct directories when you using the Upload tab. Also the demo link http://www.mixedwaves.com/filemanager_in_ckeditor/demo.html works correct and none of the files got uploaded to userfiles/ dir. Can you please check if you have correctly followed the solution especially the section that describes how to enable the quick upload tab? You can also download the demo from http://www.mixedwaves.com/filemanager_in_ckeditor.zip and check if that works correctly?
It works like a charm
Great Work
thx
c ya´s
Thankyou so much for this….. Have used FCK/CK for ages, and since using CK have either done without an uploader or used some hacky free ones I always had to recode to get working.
Spent most of yesterday and todays spare time looking for a different editor that had good WYSIWYG and HTML and upload etc for a decent licence price and found nothing
I was really in a state of dispair until I saw this post….. cracked out a couple of old builds, copied the files over, made your amends and all sweet as a nut – thanks sooooooo much.
I’m a .net mvc/aspx guy, so if I get the time, I will try to write a couple of lines to help those out too.
Dave glad it had been useful to you and you are most welcome to write some code in aspx to help those people out too. It would be a great help for them too, I get many questions about aspx but I am unable to do that due to my lack of knowledge in aspx.
I have a question regarding ckfinder settings for image folders. I have gotten the sub directories working: “\images\40″ “\images\50″ for example. In the finder I need to pass the js the customer id (40, 50) as example so that the client only can access their image folder. I think this could be done but I don’t know where the js for the finder resides. Hoping that you can help!
Rick I can’t explain it here fully, but can give you a pointer for places to explore. Most probably you will need to modify the function GetFolderRowHtml inside browser/default/frmresourceslist.html. This function creates the folder and file name links that you see on the in the browser window. Also function GetFoldersAndFiles inside connectors/php/commands.php. This function outputs the folders & files names in xml format that is parsed by javascript to display to display as file & folder list. Probably you can modify this xml to include your customers id. Use firebug to explore the ajax call that is made when browser window loads and you can get some direction from there.
Great work man
really helpful
thx a lot
Hi Penuel,
I have done some changes to implement image previews on selected folder. I changed the table for some divs.
To implement that I changed the following files:
filemanager/browser/default/frmresourceslist.html
filemanager/browser/default/browser.css
I am pasting 3 complete js functions and the necessary css class here:
in filemanager/browser/default/frmresourceslist.html :
oListManager.GetFolderRowHtml = function( folderName, folderPath )
{
// Build the link to view the folder.
var sLink = '' ;
return '' +
'' +
sLink +
'' +
' ' +
sLink +
folderName +
'' +
'' ;
}
oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )
{
// Build the link to view the folder.
var sLink = '' ;
// Get the file icon.
var sIcon = oIcons.GetIcon( fileName ) ;
if (fileName.length >= 15){
var fileNameExt = fileName.split('.').pop();
fileName = fileName.substring(0,8) + "(...)." + fileNameExt;
}
return '' +
'' +
sLink +
'' +
' ' +
sLink +
fileName +
'' +
fileSize +
' KB' +
'' ;
}
function GetFoldersAndFilesCallBack( fckXml )
{
if ( oConnector.CheckError( fckXml ) != 0 )
return ;
// Get the current folder path.
var oFolderNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' ) ;
if ( oFolderNode == null )
{
alert( 'The server didn\'t reply with a proper XML data. Please check your configuration.' ) ;
return ;
}
var sCurrentFolderPath = oFolderNode.attributes.getNamedItem('path').value ;
var sCurrentFolderUrl = oFolderNode.attributes.getNamedItem('url').value ;
// var dTimer = new Date() ;
var oHtml = new StringBuilder( '' ) ;
// Add the Folders.
var oNodes ;
oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' ) ;
for ( var i = 0 ; i < oNodes.length ; i++ )
{
var sFolderName = oNodes[i].attributes.getNamedItem('name').value ;
oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/" ) ) ;
}
// Add the Files.
oNodes = fckXml.SelectNodes( 'Connector/Files/File' ) ;
for ( var j = 0 ; j < oNodes.length ; j++ )
{
var oNode = oNodes[j] ;
var sFileName = oNode.attributes.getNamedItem('name').value ;
var sFileSize = oNode.attributes.getNamedItem('size').value ;
// Get the optional "url" attribute. If not available, build the url.
var oFileUrlAtt = oNodes[j].attributes.getNamedItem('url') ;
var sFileUrl = oFileUrlAtt != null ? oFileUrlAtt.value : encodeURI( sCurrentFolderUrl + sFileName ).replace( /#/g, '%23' ) ;
oHtml.Append( oListManager.GetFileRowHtml( sFileName, sFileUrl, sFileSize ) ) ;
}
oHtml.Append( '' ) ;
document.body.innerHTML = oHtml.ToString() ;
// window.top.document.title = 'Finished processing in ' + ( ( ( new Date() ) - dTimer ) / 1000 ) + ' seconds' ;
}
in filemanager/browser/default/browser.css :
.filesContainer {
float:none;
width:500px;
padding:10px;
}
.filesItem {
background: #CCCCCC;
float:left;
width: 100px;
height: 130px;
text-align:center;
padding:5px;
margin: 20px;
}
.filesFoto {
float:none;
width: 80px;
height: 80px;
margin: 10px;
}
.filesNombre{
float:none;
margin: 10px;
width: 80px;
}
If you wish, I could send you a zipped file.
Thanks for your job.
Santiago
Great tutorial. Made my life easier. I only have a slight problem with browse server function. It always creates “image” folder within user folder specified in confiruration.php. Is ther a way to set it to display content of user folder instead of creating new folder within?
There is no direct way of doing except if you hack into the code further.
Pingback: Enabling File Uploader with CKEditor | imdavidr blog
Hello!
Where can i put the code below for general use of all instances for editors (I want to make this so I don’t have to determin the path to each intance of editor separately.)
I use jquery adapter for calling instance of editor, using this code: $(‘#Content’).ckeditor();
The code:
CKEDITOR.replace( ‘editor1′,
{
filebrowserBrowseUrl :’js/ckeditor/filemanager/browser/default/browser.html?Connector=http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/connector.php’,
filebrowserImageBrowseUrl : ‘js/ckeditor/filemanager/browser/default/browser.html?Type=Image&Connector=http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/connector.php’,
filebrowserFlashBrowseUrl :’js/ckeditor/filemanager/browser/default/browser.html?Type=Flash&Connector=http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/connector.php’,
filebrowserUploadUrl :’http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/upload.php?Type=File’,
filebrowserImageUploadUrl : ‘http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/upload.php?Type=Image’,
filebrowserFlashUploadUrl : ‘http://www.mixedwaves.com/filemanager_in_ckeditor/js/ckeditor/filemanager/connectors/php/upload.php?Type=Flash’
});
You may use CKEditor.replaceALL() API
// Replace all elements in the page.
CKEDITOR.replaceAll( ‘myClassName’ );
More info on below link:
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.html#.replaceAll
Hello, great code. I would like to know where should I put code to resize images when they are uploaded. I looked into your code and think I should put it in upload.php file after line 229
move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
So I think after moving file I would resize it. For resizing I would use GD image library.
Do you think this would work ok?
Hi, one more thing. When i put image in editor it show ok and kode is gut. But when I get posted data all my quotes are escaped so image doesn’t show. For example in posted data I get :
How can I fix this?
I solved problem with slashes I used function stripslashes($var) on my string and is now working ok.
Brilliant work!
Brilliant work!
The only problem I had was with the last bit script:
// This is the function that sends the results of the uploading process to CKEditor.
function SendCKEditorResults ($errorNumber, $CKECallback, $fileUrl, $fileName, $customMsg ='')
{
// Minified version of the document.domain automatic fix script (#1919).
// The original script can be found at _dev/domain_fix_template.js
echo <<';
}
I changed it to:
echo 'script type="text/javascript">';