When creating a new Uploader
instance you pass a $config
object that can be used to set the uploader options:
use Hazzard\Filepicker\Uploader;
use Intervention\Image\ImageManager;
use Hazzard\Config\Repository as Config;
// Include composer autoload
require __DIR__.'/../vendor/autoload.php';
$uploader = new Uploader($config = new Config, new ImageManager(array('driver' => 'gd')));
Set options:
$config['debug'] = true;
$config['upload_dir'] = __DIR__.'/../files';
The ImageManager supports two drivers, gd
and imagick
. If you want to use the imagick
make sure you have it installed.
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 file types that should be rejected.
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
Whether to overwrite exsiting files with the same name or append a number at the end.
false
The sorting order when scaning the directory for files.
integer
1
Supported values:
Sort By | ASC | DESC |
---|---|---|
Time | 1 | 2 |
Size | 3 | 4 |
Name | 5 | 6 |
The mode used when creating directories with mkdir.
0777
Whether to keep the original image without cropping it. This allows to use the original image for later re-crop.
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,
)
),
Auto orient the image based on EXIF data. Only for the original version (with the empty key).
The image version maximum width.
The image version maximum height.
The exact image version width.
The exact image version height.
The quality of the image (0 - 100).
90
Keep the image as uploaded without any processing. Only for the original version (with the empty key).
false
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 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
An array with all the error messages.
array(
'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.',
'max_file_size' => 'The file size is too big (limit is %d KB).',
'min_file_size' => 'The file size is too small.',
'max_number_of_files' => 'Maximum number of %d files exceeded.',
'file_not_accepted' => 'The file type is not accepted.',
'abort' => 'The operation was aborted.',
'error' => 'Oops! Something went wrong.',
'not_found' => 'File not found.',
),