Reading a file with FCKeditor

I am working on a website which contains sections which the client wants to be able to update themselves.  Not very difficult stuff, just updating their pricelist, special offers, that sort of thing.  Rather than a full blown CMS (Content Management System) I opted to have the content in HTML files which can be included into the webpage as required.

All quite simple really, but I needed a way for the client to be able to edit the content online, a simple HTML editor would do but it needed to be WYSIWYG as, while the client is quite capable of updating a formatted document they don’t really want to get into HTML markup.  After a bit of research I decided that FCKeditor looked pretty good.

Looking at comments about FCKeditor it seemed that it should be pretty easy to set up and indeed it was.  Installation was easy as was getting a quick sample page working, but could I figure out how to load a file into the editor?  No I couldn’t!  I knew it must be fairly simple but I just couldn’t find any example of how to do it.  Putting a string into FCKeditor using the Value parameter was straightforward but getting an actual file in there just confounded me.

After spending most of a day hunting around the internet I just couldn’t get it working properly.  I think I must just be more stupid than the average FCKeditor developer.  But the next day ( problems often look easier the next day) after a little more searching I managed to figure out how to load a file into FCKeditor.  So I thought I’d put the solution on this blog to save anyone else as silly as me a lot of time.

It is of course quite simple.  The value parameter for FCKeditor must be a string, this is then the starting text in the editor window, the trick is to make your file into a string.

Using PHP I prepared the following test page;

include_once(“fckeditor/fckeditor.php”) ;
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>
<html xmlns=””>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Amend Pricelist</title>
<form action=”sampleposteddata.php” method=”post” target=”_blank”>

// Read the file into an array
$file_array = file(“pricelist.php”);

// Convert the array into a string
$file_contents = implode(‘ ‘,$file_array);

$oFCKeditor = new FCKeditor(‘FCKeditor1’) ;
$oFCKeditor->BasePath = ‘/fckeditor/’ ;

// Use the string as the initial value for FCKeditor

$oFCKeditor->Value = $file_contents ;

$oFCKeditor->Width  = ‘700’ ;
$oFCKeditor->Height = ‘750’ ;
$oFCKeditor->Create() ;
<br />
<input type=”submit” value=”Submit”>

And it worked!  I had managed to load a file into FCKeditor.  There may be a better way of doing this, and I would love to hear about it if someone knows better, but it does the job.

I hope this blog saves someone else a bit of headscratching.

Tags: , , , ,

4 Responses to “Reading a file with FCKeditor”

  1. Great – thanks for that. Now I would just love to know how to do this with javascript. I have a site to write with no server-side processing at all (how thoughtless).

    Still, is is a great starting-point.

  2. Paupl says:

    Thanks mate, the first part of your post is exactly what i’m in the middle of now. Your a champ.

  3. LinuxRich says:

    Thank you so much. This has help a lot. Thank you again. 🙂

  4. prathiba says:

    hi.. thanks for ur valuable msg.. actually i want to find the string length wh i enter in the textarea. how can i do that.. i searched a lot whole day not gettng really how to do that with the php.i want to find the lenght of the string and also to remove the code is

    fck editor code is
    BasePath = ‘../fckeditor/’ ;
    $oFCKeditor->Value = html_entity_decode($oFCKeditor->descrdata);
    $oFCKeditor->Width = ‘700px’ ;
    $oFCKeditor->Height = ‘350px’ ;

    $oFCKeditor->Create() ;
    i tried a lot with the strlen() but its showng the length of the string with the whitespaces if i enter 123 in first line and 234 in 2nd line..its showng as 25i want it to be displayed as 123234 without the space..please anyone help me wr i need to write the code

    thanking you

Leave a Reply