Ckeditor – not allow posting of images from the local harddrive

Within the CKEditor you can also add on to the prototypes that allow more control of what is allowed on your website.

Sometimes you do not want to allow the user to copy and paste local files to the CKEditor so this is what I done to remove the file:// from within the img tag within the copy and paste with using the CKEditor htmlDataProcessor group of functions, in this case the ‘toHtml’ function which is called when the user pastes any content into the CKEditor window. All I am doing it using the regular expression to search for the <img src=”file .. and replace with a <mg tag> which when they double click on that it will open the CKEditor’s image browser (which you can include a upload part to it as well 🙂 )

CKEDITOR.htmlDataProcessor.prototype.toHtml = function( data, fixForBody )
  {
    return data.replace(/\<img src=\"file:([^\>])*\>/ig,"<img title=\"Please use the Media/Image uploader because can not show files on your harddrive\" alt=\"Please use the Media/Image uploader because can not show files on your harddrive\"/>");
}

It was very helpful for me.