0

I have KCFinder integrated into KCEditor for image uploads in a Codeigniter site. When I create a Page, it works. I can upload images to the server and insert them into a page. But when I get back the page from MySQL into CKEditor for editing, KCFinder throws a 404 error when I try to browse for an image.

The problem is that when editing, the image browser gets the URL wrong! But both the edit page and the create page are linking to the same KCFinder folder so I don't understand why it breaks during page edit.

Here is how the URLs are in ckeditor's config.js file:

   config.filebrowserBrowseUrl = '../kcfinder/browse.php?opener=ckeditor&type=files';
   config.filebrowserImageBrowseUrl = '../kcfinder/browse.php?opener=ckeditor&type=images';
   config.filebrowserFlashBrowseUrl = '../kcfinder/browse.php?opener=ckeditor&type=flash';
   config.filebrowserUploadUrl = '../kcfinder/upload.php?opener=ckeditor&type=files';
   config.filebrowserImageUploadUrl = '../kcfinder/upload.php?opener=ckeditor&type=images';
   config.filebrowserFlashUploadUrl = '../kcfinder/upload.php?opener=ckeditor&type=flash';

The only way I could solve this problem was to use an Absolute URL. So I replaced ../ with http://localhost.dev for all the paths, like so ...

config.filebrowserBrowseUrl = 'http://localhost.dev/kcfinder/browse.php?opener=ckeditor&type=files';  

This solves the problem but I don't like Absolute URLs for situations like this for portability reasons (I have to change the URL whenever I move the site to a different environment). Is there a way I can solve this issue and maintain relative URLs? N/B Any painless alternatives are most welcome.

Kal2001
  • 27
  • 1
  • 9
  • so you want to access **base_url** or **site_url** from js. so whenever you change or move your site than it would not create any issue. is this you want ? – Raj Jagani Jun 29 '16 at 05:16
  • Raj thanks. Yes something like that but I thought its i=unvailable inside a JS file. It would have solved the problem. – Kal2001 Jun 29 '16 at 12:22

1 Answers1

1

If KCFinder is in the plugins folder of your CKEditor installation:

config.filebrowserBrowseUrl = CKEDITOR.getUrl( CKEDITOR.plugins.getPath( 'kcfinder' ) + 'browse.php?type=files' );
config.filebrowserImageBrowseUrl = CKEDITOR.getUrl( CKEDITOR.plugins.getPath( 'kcfinder' ) + 'browse.php?type=images' );
config.filebrowserFlashBrowseUrl = CKEDITOR.getUrl( CKEDITOR.plugins.getPath( 'kcfinder' ) + 'browse.php?type=flash' );
config.filebrowserUploadUrl = CKEDITOR.getUrl( CKEDITOR.plugins.getPath( 'kcfinder' ) + 'upload.php?type=files' );
config.filebrowserImageUploadUrl = CKEDITOR.getUrl( CKEDITOR.plugins.getPath( 'kcfinder' ) + 'upload.php?type=images' );
config.filebrowserFlashUploadUrl = CKEDITOR.getUrl( CKEDITOR.plugins.getPath( 'kcfinder' ) + 'upload.php?type=flash' );
user4762971
  • 126
  • 4
  • No further tweaks. I just implemented the solution. I Pasted the code and moved the KC Folder and after a refresh, it just worked! user4762971 you are the BEST! Thanks so very muck, you have saved me from using absolute URLs. – Kal2001 Jun 29 '16 at 13:11