Article · Mecha CMS

Updates.

CKEditor’s Image Upload Path

Author: Taufik Nurrohman · 410 Views

Tweet

Configure custom image upload path for neat file structure.

Did you know that our CKEditor extension has ability to set custom image upload path? By default, the uploaded images will be stored in the ASSET folder, in a folder named as the image file extension. This is the default location path where the image will be stored if we upload an image named as Picture (Copy 1).jpg:

.\www\lot\asset\jpg\picture-copy-1.jpg

The default image upload path setting can be found in the configuration file. Open lot\extend\c-k-editor\lot\state\config.php to customize:

<?php

return [
    …
    …
    'filebrowserImageUploadPath' => 'lot/asset/%‌{‌extension‌}‌%/%‌{‌name‌}‌%.%‌{‌extension‌}‌%'
];

Some candy syntax are available to customize the filebrowserImageUploadPath property:

SyntaxValue
%‌{‌date‌}‌%A Date instance with its properties.
%‌{‌extension‌}‌%The current file extension.
%‌{‌hash‌}‌%Random string generated by Guardian::hash().
%‌{‌id‌}‌%Unique ID generated by PHP uniqid().
%‌{‌name‌}‌%The current file name without file extension.

So, for example, if you set the filebrowserImageUploadPath to lot/asset/foo/bar/%‌{‌name‌}‌%.%‌{‌extension‌}‌%, then the image you have uploaded will be stored as:

.\www\lot\asset\foo\bar\picture-copy-1.jpg

And if you set the filebrowserImageUploadPath to lot/asset/foo/bar/%‌{‌id‌}‌%.%‌{‌extension‌}‌%, then the image you have uploaded will be stored as:

.\www\lot\asset\foo\bar\5a6d4215e1e65.jpg

And this is how to set the configuration value so that the uploaded images will be automatically stored by the file upload date:

<?php

return [
    …
    …
    'filebrowserImageUploadPath' => 'lot/asset/%‌{‌date.year‌}‌%-%‌{‌date.month‌}‌%-%‌{‌date.day‌}‌%/%‌{‌name‌}‌%.%‌{‌extension‌}‌%'
];

Result will be like:

.\www\lot\asset\2018-01-28\picture-copy-1.jpg

2011100000

0 Comments

No comments yet.