{"id":5,"date":"2008-05-09T19:54:02","date_gmt":"2008-05-09T19:54:02","guid":{"rendered":"http:\/\/cotsweb.com\/blog\/?p=5"},"modified":"2009-09-09T11:07:51","modified_gmt":"2009-09-09T10:07:51","slug":"reading-a-file-with-fckeditor","status":"publish","type":"post","link":"https:\/\/www.cotsweb.com\/blog\/reading-a-file-with-fckeditor-5.html","title":{"rendered":"Reading a file with FCKeditor"},"content":{"rendered":"<p>I am working on a website which contains sections which the client wants to be able to update themselves.\u00a0 Not very difficult stuff, just updating their pricelist, special offers, that sort of thing.\u00a0 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.<\/p>\n<p>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&#8217;t really want to get into HTML markup.\u00a0 After a bit of research I decided that<a title=\"FCKeditor HTML text editor homepage\" href=\"http:\/\/www.fckeditor.net\/\" target=\"_blank\"> FCKeditor<\/a> looked pretty good.<\/p>\n<p>Looking at comments about FCKeditor it seemed that it should be pretty easy to set up and indeed it was.\u00a0 Installation was easy as was getting a quick sample page working, but could I figure out how to load a file into the editor?\u00a0 No I couldn&#8217;t!\u00a0 I knew it must be fairly simple but I just couldn&#8217;t find any example of how to do it.\u00a0 Putting a string into FCKeditor using the Value parameter was straightforward but getting an actual file in there just confounded me.<\/p>\n<p>After spending most of a day hunting around the internet I just couldn&#8217;t get it working properly.\u00a0 I think I must just be more stupid than the average FCKeditor developer.\u00a0 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.\u00a0 So I thought I&#8217;d put the solution on this blog to save anyone else as silly as me a lot of time.<\/p>\n<p>It is of course quite simple.\u00a0 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.<\/p>\n<p>Using PHP I prepared the following test page;<\/p>\n<blockquote><p>&lt;?php<br \/>\ninclude_once(&#8220;fckeditor\/fckeditor.php&#8221;) ;<br \/>\n?&gt;<br \/>\n&lt;!DOCTYPE html PUBLIC &#8220;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&#8221;&gt;<br \/>\n&lt;html xmlns=&#8221;http:\/\/www.w3.org\/1999\/xhtml&#8221;&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=iso-8859-1&#8243; \/&gt;<br \/>\n&lt;title&gt;Amend Pricelist&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;form action=&#8221;sampleposteddata.php&#8221; method=&#8221;post&#8221; target=&#8221;_blank&#8221;&gt;<br \/>\n&lt;?php<\/p>\n<p>\/\/ Read the file into an array<br \/>\n$file_array = file(&#8220;pricelist.php&#8221;);<\/p>\n<p>\/\/ Convert the array into a string<br \/>\n$file_contents = implode(&#8216; &#8216;,$file_array);<\/p>\n<p>$oFCKeditor = new FCKeditor(&#8216;FCKeditor1&#8217;) ;<br \/>\n$oFCKeditor-&gt;BasePath = &#8216;\/fckeditor\/&#8217; ;<\/p>\n<p>\/\/ Use the string as the initial value for FCKeditor<\/p>\n<p>$oFCKeditor-&gt;Value = $file_contents ;<\/p>\n<p>$oFCKeditor-&gt;Width\u00a0 = &#8216;700&#8217; ;<br \/>\n$oFCKeditor-&gt;Height = &#8216;750&#8217; ;<br \/>\n$oFCKeditor-&gt;Create() ;<br \/>\n?&gt;<br \/>\n&lt;br \/&gt;<br \/>\n&lt;input type=&#8221;submit&#8221; value=&#8221;Submit&#8221;&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p><\/blockquote>\n<p>And it worked!\u00a0 I had managed to load a file into FCKeditor.\u00a0 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.<\/p>\n<p>I hope this blog saves someone else a bit of headscratching.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>I am working on a website which contains sections which the client wants to be able to update themselves.\u00a0 Not very difficult stuff, just updating their pricelist, special offers, that sort of thing.\u00a0 Rather than a full blown CMS (Content Management System) I opted to have the content in HTML files which can be included [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20,19,18],"tags":[73,74,145,144,75],"_links":{"self":[{"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/posts\/5"}],"collection":[{"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/comments?post=5"}],"version-history":[{"count":3,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/posts\/5\/revisions"}],"predecessor-version":[{"id":89,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/posts\/5\/revisions\/89"}],"wp:attachment":[{"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/media?parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/categories?post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/tags?post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}