Prasad Patel
Prasad Patel

Reputation: 747

How to restrict image upload maxsize to 2MB in CKEditor?

I am working on a requirement of upload image in 'CKEditor' where the image that is uploaded should be below 2MB size. I am using 'CKFinder' for the image upload, I know that there is a 'maxSize' option for images in 'ckfinder\config.php' file, Initially maxSize=0 is there that I have changed it to '2000' and after that I tried to upload image above 2MB but still it is accepting that image to upload. I observed here what is happening whenever user uploads an image in CKEditor is It is doing image compression automatically and the 2MB or above image is getting compressed to KB's. Below is the code of config.php file:

ckeditor/ckfinder/config.php

$config['resourceTypes'][] = array(
  'name'              => 'Images',
  'directory'         => 'images',
  'maxSize'           => 2000,
  'allowedExtensions' => 'bmp,gif,jpeg,jpg,png',
  'deniedExtensions'  => '',
  'backend'           => 'default'
);

ckeditor/config.js

CKEDITOR.editorConfig = function( config ) {
  config.filebrowserBrowseUrl = "/ckeditor/ckfinder/ckfinder.html";
  config.filebrowserImageBrowseUrl = "/ckeditor/ckfinder/ckfinder.html?type=Images";
  config.filebrowserFlashBrowseUrl = "/ckeditor/ckfinder/ckfinder.html?type=Flash";
  config.filebrowserUploadUrl = "/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files";
  config.filebrowserImageUploadUrl = "/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images";
  config.filebrowserFlashUploadUrl = "/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash";
  config.language = "en";
  config.uiColor = "#F7B42C";
  config.height = 300;
  config.toolbarCanCollapse = true
};

My questions here are, I am confused of whether 'maxSize' is in KB's or MB's in config.php file? how to restrict image maxSize to allow images equals to or below 2 MB in CKEditor? Any help would be appreciated. Thanks.

Upvotes: 0

Views: 6282

Answers (1)

f1ames
f1ames

Reputation: 1744

You may refer to CKFinder PHP connector official docs on resourceTypes:

The maximum size of the uploaded image defined in bytes. A shorthand notation is also supported: G, M, K (case insensitive). 1M equals 1048576 bytes (one Megabyte), 1K equals 1024 bytes (one Kilobyte), 1G equals 1 Gigabyte.

This question have been also already answered on CKEditor Github issue page.

Upvotes: 0

Related Questions