Live demo for mLIB Media Manager 1.11


mLIB media manager is a file management tool that helps to upload and import files easily. It is similar to WordPress's media uploader, so if you are familiar with it, it will be very easy for you to understand.

Example 1 : Choose a single photo and get its URL

This example shows very basic usage. When you click choose button, mlib UI will pop-up. You can either upload files from your PC or select a file from already uploaded file. Please look for horizontal double arrow button, then click Insert from existing to view old files. You can click a thumbnail to select it, then press Insert button.

  • OUTPUT
  • HTML
  • JAVASCRIPT

Allowed image filetypes are jpg, jpeg, png, gif. You can click HTML or JAVASCRIPT tabs to see their markups.

<input type="text" id="pic1" name="pic1" />
<button id="pic1btn">Choose</button>
jQuery(document).ready(function(){
jQuery('#pic1btn').mlibready({returnto:'#pic1', maxselect:1});
});

Example 2 : Choose a single photo and get formatted output.

Choose a single photo and get its thumbnail, size, upload date, title and description in pre-formatted output. It can be applied to any HTML element, not just textbox, textarea or other form elements. Its upto you how you will handle your data.

  • OUTPUT
  • HTML
  • JAVASCRIPT

Click on the button below and upload or choose a picture just like you did in example 1 above. This text will be replaced with image information as soon as you click import button.

When upload window is open, if you click double arraw button, you will see Import options tab. Click on it and here you can edit the output for receiving. Please visit return-type in usage instructions for complete information.

<div id="info1"></div>
<button id="info1btn">Get photo information</button>
jQuery(document).ready(function(){
jQuery('#info1btn').mlibready({returnto:'#info1', returnas:10, admin:1, maxselect:1});
});

Example 3 : Choose multiple photos and get file name in textarea.

Here we are not going to get the full URL, as happened in example 1. Only uploaded file names will be received so that you may use them with databases more easily. Also we are not setting any maximum limit of files this time.

  • OUTPUT
  • HTML
  • JAVASCRIPT

Once you have selected many files, you can see that filenames are separated using a space and newline charector. Also you may note that only filenames are displayed instead of full URL.

<textarea id="mult1" name="mult1"></textarea>
<button id="mult1btn">Choose</button>

While using Insert from existing option, you can see that files used in previous examples are not shown here. This is because we have used a different folderID for this example. folderID can be alphanumeric charectors only.

jQuery(document).ready(function(){
jQuery('#mult1btn').mlibready({returnto:'#mult1', folderID:'ttyy67', returnas:2});
});

Example 4 : Create clickable thumbnail gallery with 3 - 10 photos

This time you will see additional tab in uploader called Import options. To activate this mode, admin:1 needs to be added to code. Here you can create, modify or delete different markups. Please check JAVASCRIPT tab for better understanding.

  • OUTPUT
  • HTML
  • JAVASCRIPT

To create gallery, we will use a different, custom made markup using returnas. Also we have used same folderID from previous example. Hence you can use same photos else you can upload new ones.

<div id="pics2"></div>
<button id="pics2btn">Choose Photos</button>
jQuery(document).ready(function(){
jQuery('#pics2btn').mlibready({
returnto:'#pics2',
maxselect:10,
minselect:3,
folderID:'ttyy67',
returnas:6,
admin:1
});
});

Example 5 : Some documents for download, 3 - 5 files.

This example will work with different file types. We must use allowed option to modify the file types that can be uploaded. Please note that even if you allow some format here that is not allowed in the mlib-config.php file, it wont upload. This works like an added security layer to prevent uploading malicious files.

  • OUTPUT
  • HTML
  • JAVASCRIPT

Allowed file types are pdf, doc, docx, ppt, pptx, xls, xlsx, txt, zip, rar, apk. JPG, PNG and GIF are also supported by script but not by this example, hence images will not upload.

<div id="docs1"></div>
<button id="docs1btn">Choose Files</button>
jQuery(document).ready(function(){
jQuery('#docs1btn').mlibready({
returnto:'#docs1',
maxselect:5,
minselect:3,
folderID:'files675',
allowed:'pdf,doc,docx,ppt,pptx,xls,xlsx,txt,zip,rar,apk',
returnas:3,
admin:1
});
});

Example 6 : Run a custom javascript function.

Sometimes, you may want to run a custom javascript function to modify the output even before it is displayed. We will make use of runfunction option of the plugin.

  • OUTPUT
  • HTML
  • JAVASCRIPT

At the bottom right of this tab, you can see some text in red color, showing no of files and their total size. When you have selected the files, that text will change according to the selection.

0 files selected, 0 bytes total
<textarea id="func1" name="func1"></textarea>
<button id="func1btn">Choose</button>
<span id="func1span">0 files selected, 0 bytes total</span>

// this function processes the input and sets output to external element
function my_custom_function(a, b) {
    const files = a.split("\n");
    var bytes = 0;
    var f = 0;
    for (var i = 0; i < files.length; i++) {
        var fdata = files[i].trim();
        if (fdata.length > 0) {
            const xdata = fdata.split("|");
            bytes = bytes + parseInt(xdata[1]);
            f++;
        }
    }
    document.getElementById('func1span').innerHTML = f + ' files selected, ' + bytes + ' bytes total';
}

// setting options for mlib
jQuery(document).ready(function() {
    jQuery('#func1btn').mlibready({
        returnto: '#func1',
        folderID: 'ttyy67',
        runfunction: 'my_custom_function',
        returnas: 9
    });
});

Example 7 : Integrating with TinyMCE editor.

TinyMCE editor integration works for self-hosted version only. Also all versions of TinyMCE 4 is compatible with this version of mLIB media manager. However you need to know and understand how tinyMCE works.

  • OUTPUT
  • INTEGRATION
  • HTML
  • JAVASCRIPT

Below you can see my customized version of tinyMCE WYSIWYG editor in action. To use mLIB, just click on Insert Media button.

  • If you havent already, Click here to download tinyMCE 4.9.11 right now.
  • Extract and then copy the contents of tinymce/js/tinymce/ folder to the mlib/mlib-includes/tinymce/ folder.
  • Make sure that path of tinymce.min.js is correct and it is accessible via URL like :
    http://your-web-site.com/mlib/mlib-includes/tinymce/tinymce.min.js
  • In the head tag of html page, you need to load the javascripts of tinyMCE editor and its plugin.

    <script type="text/javascript" src="http://your-site-here.com/mlib/mlib-includes/tinymce/tinymce.min.js"></script>
    <script type="text/javascript" src="http://your-site-here.com/mlib/mlib-includes/js/mce_mlib.js"></script>
  • Integration is complete. Look HTML and JAVASCRIPT tabs for usage information.

Use below html anywhere in page where you want tinyMCE editor to appear.

<textarea name="mytextarea" rows="15" id="mytextarea"></textarea>
tinymce.init({
selector: '#mytextarea',
plugins: 'mce_mlib',
toolbar: 'mce_mlib | bold italic underline | alignleft aligncenter alignright alignjustify | undo redo'
});

Example 8 : Integrating with CKeditor.

CKeditor integration works for self-hosted version only. Also all versions of CKeditor 4 is compatible with this version of mLIB media manager.

  • OUTPUT
  • INTEGRATION
  • HTML
  • JAVASCRIPT

Below you can see my customized version of CKeditor in action. To use mLIB, just click on Insert Media button.

  • If you havent already, Click here to download ckeditor 4.22.1 right now.
  • Extract and then copy the contents of ckeditor/ folder to the mlib/mlib-includes/ckeditor/ folder.
  • Make sure that path of ckeditor.js is correct and it is accessible via URL like :
    http://your-web-site.com/mlib/mlib-includes/ckeditor/ckeditor.js
  • Copy the contents inside ckeditor_plugin folder to ckeditor/plugins folder.
  • Open the config.js file in ckeditor folder in a text editor and add an extra line in configuration so that it becomes
    CKEDITOR.editorConfig = function( config ) {
    config.extraPlugins = 'medialib';
    };
  • In the head tag of html page, you need to load the main javascript of CKeditor.
    <script src="http://your-site-here.com/mlib/mlib-includes/ckeditor/ckeditor.js"></script>
  • Integration is complete. Look HTML and JAVASCRIPT tabs for usage information.

Use below html where you want CKeditor to appear.

<textarea name="ckedit" rows="15" id="ckedit"></textarea>
editor = CKEDITOR.replace('ckedit');

This is the end of live demo for mLIB media manager 1.1. For documentation, please visit usage instructions for complete information.

A product of phploaded.com