When creating a new instance of Hazzard\Filepicker\Uploader
you pass a Hazzard\Config\Repository
that you use to set configuration options:
use Hazzard\Filepicker\Uploader;
use Intervention\Image\ImageManager;
use Hazzard\Config\Repository as Config;
$uploader = new Uploader($config = new Config, new ImageManager);
Set configuration options:
$config['debug'] = true;
// or
$config->set('upload_dir', __DIR__.'/../files');
The second argument is an instance of Intervention Image which supports two image processing extensions: GD and Imagick. The default driver is GD, to change it just pass the configuration as an array directly into the ImageManager instance:
$manager = new ImageManager(array('driver' => 'imagick'));
$uploader = new Uploader($config = new Config, $manager);
Notice: Make sure you have installed Imagick if you want to use it.
If enabled, more detailed error messages will be shown on every error that occurs, otherwise a simple generic error is shown.
false
The directory where the files are uploaded. Make sure to use absolute paths and the directory has read/write permissions.
n/a
__DIR__.'/../files'
The url to the directory where the files are uploaded.
n/a
http://localhost/filepicker/files
The url to the file where the ajax requests are sent.
http://localhost/filepicker/uploader/index.php
The minimum file size required (in Bytes).
1
1000
(= 1 Kilobyte)The maximum file size allowed (in Bytes).
n/a
10000000
(= 10 Megabyes)The accepted file types.
n/a
jpg|png|txt|pdf|mp3
The accepted file types regular expresion.
n/a
The rejected file types.
php|phtml|php3|php5|phps
Files that should be handled as images. Used for validation and creating image versions.
gif|jpg|jpeg|png
File types that should be handled as inline files, used when php_download is enabled.
gif|jpg|jpeg|png|pdf|txt|js|css
The maximum number of files allowed to be uploaded to the upload_dir
n/a
20
Whether to use direct file links or donwload the files via PHP.
false
The min/max width/height for image type files.
1
/ n\a
An array with image versions that are created for each uploaded image. The key of each element will be the version name and the value will be an array contain the version constraints. The default version will have an empty key.
array(
'' => array(
'auto_orient' => true,
),
'thumb' => array(
'crop' => true,
'max_width' => 100,
'max_height' => 100,
),
),
Auto orient the image based on EXIF data.
Create a square image instead of just scaling the image version.
The image version maximum width.
The image version maximum height.
The quality of the image (0 - 100).
90
Custom directory where the image version is created. Make sure to use absolute paths and the directory has read/write permissions. If is the same as the global upload_dir directory then, the image version will be named like this:filename-version.jpg
.
. '/version'
__DIR__.'/../files'
Custom url to the directory where the image version is created.
. '/version'
http://localhost/filepicker/files
Callback fired before creating the image version. The callback has two arguments, $image
which is an instance of \Intervention\Image\Image (see Intervention Image) and $version
, the version name. Returning false
will cancel the crop.
n/a
Example:
/**
*
* @param \Intervention\Image\Image $image
* @param string $version
*/
'before' => function($image, $version) {
// return false;
},
Callback fired after creating the image version. Same as the before callback, except with no return.
n/a
Whether to keep the original image without cropping it. This allows to use the original image for later re-crop.
false
The alphabetical sorting order when scaning the directory for files with scandir.
Use 0
for ascending order, and 1
for descending order. In PHP 5.4 you can use SCANDIR_SORT_NONE
for unsorted.
0
The mode used when creating directories with mkdir.
0777
An array with all error messages.
array(
'no_file' => 'No file was uploaded.',
'max_width' => 'Image exceeds maximum width of %d pixels.',
'min_width' => 'Image requires a minimum width of %d pixels.',
'max_height' => 'Image exceeds maximum height of %d pixels.',
'min_height' => 'Image requires a minimum height of %d pixels.',
'image_resize' => 'Failed to resize image versions (%s).',
'upload_failed' => 'Failed to upload the file (error %d).',
'max_file_size' => 'The file exceeds the maximum allowed file size (limit is %d KB).',
'min_file_size' => 'The file size is too small.',
'accept_file_types' => 'The file type is not allowed.',
'max_number_of_files' => 'Maximum number of files exceeded.',
'error' => 'Oops! Something went wrong.',
'abort' => 'The operation was aborted.',
'404' => 'File not found.',
'401' => 'Unauthorized.',
),