Skip to content

Commit

Permalink
No thumbnails created for .jpeg upload.
Browse files Browse the repository at this point in the history
Adds a configuration option to application/config/indicia.php in which different file types can be specified.
This is used to determine a.) whether a file can be uploaded and b.) whether a thumbnail image should be generated.
If absent, allows upload of png,gif,jpg,jpeg,mp3,wav,pdf and creates thumbnails for png,gif,jpg,jpeg.
  • Loading branch information
JimBacon committed Aug 5, 2015
1 parent 7339a9c commit 4c8813e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
14 changes: 14 additions & 0 deletions application/config/indicia_dist.php
Expand Up @@ -109,6 +109,20 @@
)
);

/**
* Declare the different file types that can be uploaded by file extension,
* grouped according to media type.
* Used in modules/indicia_svc_data/controllers/services/data.php to restrict
* file types.
* Used in application/libraries/MY_Image.php to determine if uploaded file
* should have thumbnails created.
*/
$config['upload_file_type'] = array(
'image' => array('jpg', 'gif', 'png', 'jpeg'),
'pdf' => array('pdf'),
'audio' => array('mp3', 'wav')
);

/**
* Should the warehouse return http status codes when a web service error occurs.
* This setting should be set to false if compatibility with Indicia clients running
Expand Down
2 changes: 1 addition & 1 deletion application/i18n/en_GB/form_error_messages.php
Expand Up @@ -197,7 +197,7 @@
'valid' => 'The file is being tagged as invalid.',
'required' => 'The file has not been uploaded to the warehouse. One possible reason is that its size may exceed the server upload limits.',
'size' => 'The file size exceeds the maximum allowed.',
'type' => 'The file is not one of the allowed types [png,gif,jpg,jpeg].',
'type' => 'The file is not one of the allowed types.',
'default' => 'Invalid file.',
),
);
Expand Down
13 changes: 12 additions & 1 deletion application/libraries/MY_Image.php
Expand Up @@ -45,9 +45,20 @@ public static function create_image_files($uploadpath, $filename, $subdir = "",
$uploadpath = $uploadpath.'/';
if ($subdir != "" && substr($subdir,-1) != '\\' && substr($subdir,-1) != '/')
$subdir = $subdir.'/';

// Test file extension against allowed types
$fileParts = explode('.', $filename);
$ext = strtolower(array_pop($fileParts));
if (in_array($ext, Image::$allowed_types)) {
$config = kohana::config('indicia.upload_file_type');
if (!$config || !array_key_exists('image', $config)) {
// Default list if no entry in config.
$allowed_image = in_array($ext, array('jpg', 'gif', 'png', 'jpeg'));
}
else {
$allowed_image = in_array($ext, $config['image']);
}

if ($allowed_image) {
// website specific config available?
$config = $website_id ? kohana::config('indicia.image_handling_website_'.$website_id) : false;
// if not, is there a default config setting
Expand Down
15 changes: 14 additions & 1 deletion modules/indicia_svc_data/controllers/services/data.php
Expand Up @@ -827,9 +827,22 @@ public function handle_media()
// media.
// Upload size
$ups = Kohana::config('indicia.maxUploadSize');
// Get comma separated list of allowed file types
$config = kohana::config('indicia.upload_file_type');
if (!$config) {
// Default list if no entry in config.
$types = 'png,gif,jpg,jpeg,mp3,wav,pdf';
}
else {
// Implode array of arrays.
$types = implode(',', array_map(function($a){
implode(',', $a);
}, $config));
}

$_FILES = Validation::factory($_FILES)->add_rules(
'media_upload', 'upload::valid', 'upload::required',
'upload::type[png,gif,jpg,jpeg,mp3,wav,pdf]', "upload::size[$ups]"
"upload::type[$types]", "upload::size[$ups]"
);
if ($_FILES->validate())
{
Expand Down

0 comments on commit 4c8813e

Please sign in to comment.