PHP code example of getolympus / olympus-upload-field

1. Go to this page and download the library: Download getolympus/olympus-upload-field library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

getolympus / olympus-upload-field example snippets


return \GetOlympus\Dionysos\Field\Upload::build('my_upload_field_id', [
    'title'       => 'What\'s your flavor?',
    'can_upload'  => false,
    'default'     => [],
    'description' => 'Tell me what\'s your flavour!',
    'multiple'    => false,
    'type'        => 'image',
    'size'        => 'thumbnail',

    /**
     * Texts definition
     * @see the `Texts definition` section below
     */
    't_addblock_description'  => 'Click on the "+" button to add a media.',
    't_addblocks_description' => 'Click on the "+" button to add medias.',
    't_cannot_upload'         => 'It seems you are not able to upload files.',
    't_name_label'            => 'Edit the legend',
    't_addblock_label'        => 'Add',
    't_editblock_label'       => 'Edit',
    't_removeblock_label'     => 'Remove',
]);

// Get upload from Database
$upload = get_option('my_upload_field_id', []);

if (!empty($upload)) {
    foreach ($upload as $img) {
        echo '<figure id="'.$img['id'].'">';
        echo '<img src="'.$img['url'].'" width="'.$img['width'].'" height="'.$img['height'].'" alt="'.esc_html($img['name']).'" />';
        echo '<figcaption>'.$img['name'].'</figcaption>';
        echo '</figure>';
    }
}