2017 © Pedro Peláez
 

lithium-library li3_uploadable

This plugin will upload files via HTTP POST uploads only since it relies on $_FILES to get the source path.

image

johnny13/li3_uploadable

This plugin will upload files via HTTP POST uploads only since it relies on $_FILES to get the source path.

  • Friday, September 19, 2014
  • by johnnyfortune
  • Repository
  • 1 Watchers
  • 0 Stars
  • 69 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Upload files via $_FILES in the Lithium framework

This plugin will upload files via HTTP POST uploads only since it relies on $_FILES to get the source path., (*1)

Dependencies

li3_behaviors by @jails, (*2)

Installation

Clone the code to your library directory (or add it as a submodule):, (*3)

cd libraries
git clone git@github.com:housni/li3_uploadable.git

If you plan to use the Imagine (by @avalanche123) strategy, you also need to do:, (*4)

git submodule init && git submodule update

Include the library in in your /app/config/bootstrap/libraries.php, (*5)

Libraries::add('li3_uploadable');

Configuration

 [
        'adapter' => 'CompressionArchive',
        'strategies' => ['ZipArchive'],
        'processors' => [
            'extract' => ['{:application}/views/themes']
        ],
        'save' => '{:application}/views/themes/{:filename}.zip',
        'remove' => '{:application}/views/themes/{:filename}',
        'filters' => [
            function($self, $params, $chain) {
                $extracted = $chain->next($self, $params, $chain);
                if (file_exists($extracted['extract']['source'])) {
                    unlink($extracted['extract']['source']);
                }
                return $extracted;
            }
        ]
    ],

    /**
     * Uploads a preview image of the theme with two different styles.
     * Assuming the name of the image uploaded is `preview.png`, this will yield:
     * 1. `thumb_preview.png` at 250 x 250px
     * 2. `full_preview.png` at 1024 x 1024px
     *
     * The `Imagine` strategy depends on Imagine: https://github.com/avalanche123/Imagine
     */
    'themePreview' => [
        'adapter' => 'Image',
        'strategies' => [
            'Imagine' => [
                'implementation' => 'Imagick',
                'styles' => [
                    'thumb' => '250x250',
                    'full' => '1280x1024'
                ],
                'quality' => 100
            ]
        ],
        'save' => '{:application}/webroot/uploads/themes/{:id}/{:style}_{:basename}',
        'remove' => '{:application}/webroot/uploads/themes/{:id}',
        'url' => 'uploads/themes/{:id}/{:style}_{:basename}',
        'default' => 'img/missing-theme.png'
    ],
]);
?>

Usage

The model below assumes you are accepting a enctype="multipart/form-data" form whose fields of names directory and preview accept files., (*6)

 [
            'fields' => [
                'themeArchive' => 'directory',
                'themePreview' => 'preview'
            ],
            /**
             * You can override placeholders
             */
            'placeholders' => [
                'model' => 'MyModelName'
            ]
        ]
    ];
}
?>

In your views:, (*7)

// This will output the text value stored in themes.directory
= $theme->directory; ?>

// This will output the 250 x 250px thumb_preview.png url
<img src="<?= $theme->preview->url('thumb'); ?>" alt="Preview of theme">

Validation

Look at app/config/bootstrap/validators.php, (*8)

More Adapter => Strategy

  • MP3 => ID3
  • Vide => FFmpeg
  • PDF => wkhtmltopdf

TODO

  • Make code comply with li3_quality
  • Add more documentation
  • Add tests

The Versions

19/09 2014

dev-master

9999999-dev https://github.com/housni/li3_uploadable

This plugin will upload files via HTTP POST uploads only since it relies on $_FILES to get the source path.

  Sources   Download

The Requires

 

php model behavior lithium li3