dev-master
9999999-dev https://github.com/housni/li3_uploadableThis plugin will upload files via HTTP POST uploads only since it relies on $_FILES to get the source path.
The Requires
php model behavior lithium li3
This plugin will upload files via HTTP POST uploads only since it relies on $_FILES to get the source path.
This plugin will upload files via HTTP POST uploads only since it relies on $_FILES to get the source path., (*1)
li3_behaviors by @jails, (*2)
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');
[ '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' ], ]); ?>
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">
Look at app/config/bootstrap/validators.php
, (*8)
li3_quality
This plugin will upload files via HTTP POST uploads only since it relies on $_FILES to get the source path.
php model behavior lithium li3