update fileUploader to 9.21.0

This commit is contained in:
francois
2018-04-19 21:03:46 +02:00
parent 5a0734a357
commit 59a9e5b690
3 changed files with 67 additions and 42 deletions

View File

@@ -34,7 +34,7 @@ class Uploader extends UploadHandler
* https://blueimp.net * https://blueimp.net
* *
* Licensed under the MIT license: * Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
class UploadHandler class UploadHandler
@@ -67,12 +67,13 @@ class UploadHandler
protected $image_objects = array(); protected $image_objects = array();
function __construct($options = null, $initialize = true, $error_messages = null) { public function __construct($options = null, $initialize = true, $error_messages = null) {
$this->response = array(); $this->response = array();
$this->options = array( $this->options = array(
'script_url' => $this->get_full_url().'/'.basename($this->get_server_var('SCRIPT_NAME')), 'script_url' => $this->get_full_url().'/'.$this->basename($this->get_server_var('SCRIPT_NAME')),
'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/files/', 'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/files/',
'upload_url' => $this->get_full_url().'/files/', 'upload_url' => $this->get_full_url().'/files/',
'input_stream' => 'php://input',
'user_dirs' => false, 'user_dirs' => false,
'mkdir_mode' => 0755, 'mkdir_mode' => 0755,
'param_name' => 'files', 'param_name' => 'files',
@@ -157,18 +158,22 @@ class UploadHandler
// Command or path for to the ImageMagick identify binary: // Command or path for to the ImageMagick identify binary:
'identify_bin' => 'identify', 'identify_bin' => 'identify',
'image_versions' => array( 'image_versions' => array(
// The empty image version key defines options for the original image: // The empty image version key defines options for the original image.
// Keep in mind: these image manipulations are inherited by all other image versions from this point onwards.
// Also note that the property 'no_cache' is not inherited, since it's not a manipulation.
'' => array( '' => array(
// Automatically rotate images based on EXIF meta data: // Automatically rotate images based on EXIF meta data:
'auto_orient' => true 'auto_orient' => true
), ),
// Uncomment the following to create medium sized images: // You can add arrays to generate different versions.
// The name of the key is the name of the version (example: 'medium').
// the array contains the options to apply.
/* /*
'medium' => array( 'medium' => array(
'max_width' => 800, 'max_width' => 800,
'max_height' => 600 'max_height' => 600
), ),
*/ */
'thumbnail' => array( 'thumbnail' => array(
// Uncomment the following to use a defined directory for the thumbnails // Uncomment the following to use a defined directory for the thumbnails
// instead of a subdirectory based on the version identifier. // instead of a subdirectory based on the version identifier.
@@ -179,9 +184,13 @@ class UploadHandler
//'upload_url' => $this->get_full_url().'/thumb/', //'upload_url' => $this->get_full_url().'/thumb/',
// Uncomment the following to force the max // Uncomment the following to force the max
// dimensions and e.g. create square thumbnails: // dimensions and e.g. create square thumbnails:
//'crop' => true, // 'auto_orient' => true,
'max_width' => 80, // 'crop' => true,
'max_height' => 80 // 'jpeg_quality' => 70,
// 'no_cache' => true, (there's a caching option, but this remembers thumbnail sizes from a previous action!)
// 'strip' => true, (this strips EXIF tags, such as geolocation)
'max_width' => 80, // either specify width, or set to 0. Then width is automatically adjusted - keeping aspect ratio to a specified max_height.
'max_height' => 80 // either specify height, or set to 0. Then height is automatically adjusted - keeping aspect ratio to a specified max_width.
) )
), ),
'print_response' => true 'print_response' => true
@@ -337,7 +346,7 @@ class UploadHandler
$this->get_upload_path($file_name) $this->get_upload_path($file_name)
); );
$file->url = $this->get_download_url($file->name); $file->url = $this->get_download_url($file->name);
foreach($this->options['image_versions'] as $version => $options) { foreach ($this->options['image_versions'] as $version => $options) {
if (!empty($version)) { if (!empty($version)) {
if (is_file($this->get_upload_path($file_name, $version))) { if (is_file($this->get_upload_path($file_name, $version))) {
$file->{$version.'Url'} = $this->get_download_url( $file->{$version.'Url'} = $this->get_download_url(
@@ -373,10 +382,11 @@ class UploadHandler
$this->error_messages[$error] : $error; $this->error_messages[$error] : $error;
} }
function get_config_bytes($val) { public function get_config_bytes($val) {
$val = trim($val); $val = trim($val);
$last = strtolower($val[strlen($val)-1]); $last = strtolower($val[strlen($val)-1]);
switch($last) { $val = (int)$val;
switch ($last) {
case 'g': case 'g':
$val *= 1024; $val *= 1024;
case 'm': case 'm':
@@ -442,12 +452,12 @@ class UploadHandler
@$this->options['image_versions']['']['auto_orient'] && @$this->options['image_versions']['']['auto_orient'] &&
function_exists('exif_read_data') && function_exists('exif_read_data') &&
($exif = @exif_read_data($uploaded_file)) && ($exif = @exif_read_data($uploaded_file)) &&
(((int) @$exif['Orientation']) >= 5 ) (((int) @$exif['Orientation']) >= 5)
) { ) {
$tmp = $img_width; $tmp = $img_width;
$img_width = $img_height; $img_width = $img_height;
$img_height = $tmp; $img_height = $tmp;
unset($tmp); unset($tmp);
} }
} }
@@ -494,7 +504,7 @@ class UploadHandler
} }
// Keep an existing filename if this is part of a chunked upload: // Keep an existing filename if this is part of a chunked upload:
$uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]); $uploaded_bytes = $this->fix_integer_overflow((int)$content_range[1]);
while(is_file($this->get_upload_path($name))) { while (is_file($this->get_upload_path($name))) {
if ($uploaded_bytes === $this->get_file_size( if ($uploaded_bytes === $this->get_file_size(
$this->get_upload_path($name))) { $this->get_upload_path($name))) {
break; break;
@@ -513,7 +523,7 @@ class UploadHandler
} }
if ($this->options['correct_image_extensions'] && if ($this->options['correct_image_extensions'] &&
function_exists('exif_imagetype')) { function_exists('exif_imagetype')) {
switch(@exif_imagetype($file_path)){ switch (@exif_imagetype($file_path)){
case IMAGETYPE_JPEG: case IMAGETYPE_JPEG:
$extensions = array('jpg', 'jpeg'); $extensions = array('jpg', 'jpeg');
break; break;
@@ -543,7 +553,7 @@ class UploadHandler
// Remove path information and dots around the filename, to prevent uploading // Remove path information and dots around the filename, to prevent uploading
// into different directories or replacing hidden system files. // into different directories or replacing hidden system files.
// Also remove control characters and spaces (\x00..\x20) around the filename: // Also remove control characters and spaces (\x00..\x20) around the filename:
$name = trim(basename(stripslashes($name)), ".\x00..\x20"); $name = trim($this->basename(stripslashes($name)), ".\x00..\x20");
// Use a timestamp for empty filenames: // Use a timestamp for empty filenames:
if (!$name) { if (!$name) {
$name = str_replace('.', '-', microtime(true)); $name = str_replace('.', '-', microtime(true));
@@ -887,22 +897,32 @@ class UploadHandler
$image_oriented = false; $image_oriented = false;
if (!empty($options['auto_orient'])) { if (!empty($options['auto_orient'])) {
$image_oriented = $this->imagick_orient_image($image); $image_oriented = $this->imagick_orient_image($image);
} }
$image_resize = false;
$new_width = $max_width = $img_width = $image->getImageWidth(); $new_width = $max_width = $img_width = $image->getImageWidth();
$new_height = $max_height = $img_height = $image->getImageHeight(); $new_height = $max_height = $img_height = $image->getImageHeight();
if (!empty($options['max_width'])) {
$new_width = $max_width = $options['max_width']; // use isset(). User might be setting max_width = 0 (auto in regular resizing). Value 0 would be considered empty when you use empty()
if (isset($options['max_width'])) {
$image_resize = true;
$new_width = $max_width = $options['max_width'];
} }
if (!empty($options['max_height'])) { if (isset($options['max_height'])) {
$image_resize = true;
$new_height = $max_height = $options['max_height']; $new_height = $max_height = $options['max_height'];
} }
if (!($image_oriented || $max_width < $img_width || $max_height < $img_height)) {
$image_strip = (isset($options['strip']) ? $options['strip'] : false);
if ( !$image_oriented && ($max_width >= $img_width) && ($max_height >= $img_height) && !$image_strip && empty($options["jpeg_quality"]) ) {
if ($file_path !== $new_file_path) { if ($file_path !== $new_file_path) {
return copy($file_path, $new_file_path); return copy($file_path, $new_file_path);
} }
return true; return true;
} }
$crop = !empty($options['crop']); $crop = (isset($options['crop']) ? $options['crop'] : false);
if ($crop) { if ($crop) {
$x = 0; $x = 0;
$y = 0; $y = 0;
@@ -942,7 +962,7 @@ class UploadHandler
} }
break; break;
} }
if (!empty($options['strip'])) { if ( $image_strip ) {
$image->stripImage(); $image->stripImage();
} }
return $success && $image->writeImage($new_file_path); return $success && $image->writeImage($new_file_path);
@@ -1056,7 +1076,7 @@ class UploadHandler
protected function handle_image_file($file_path, $file) { protected function handle_image_file($file_path, $file) {
$failed_versions = array(); $failed_versions = array();
foreach($this->options['image_versions'] as $version => $options) { foreach ($this->options['image_versions'] as $version => $options) {
if ($this->create_scaled_image($file->name, $version, $options)) { if ($this->create_scaled_image($file->name, $version, $options)) {
if (!empty($version)) { if (!empty($version)) {
$file->{$version.'Url'} = $this->get_download_url( $file->{$version.'Url'} = $this->get_download_url(
@@ -1072,7 +1092,7 @@ class UploadHandler
} }
if (count($failed_versions)) { if (count($failed_versions)) {
$file->error = $this->get_error_message('image_resize') $file->error = $this->get_error_message('image_resize')
.' ('.implode($failed_versions,', ').')'; .' ('.implode($failed_versions, ', ').')';
} }
// Free memory: // Free memory:
$this->destroy_image_object($file_path); $this->destroy_image_object($file_path);
@@ -1109,7 +1129,7 @@ class UploadHandler
// Non-multipart uploads (PUT method support) // Non-multipart uploads (PUT method support)
file_put_contents( file_put_contents(
$file_path, $file_path,
fopen('php://input', 'r'), fopen($this->options['input_stream'], 'r'),
$append_file ? FILE_APPEND : 0 $append_file ? FILE_APPEND : 0
); );
} }
@@ -1176,7 +1196,7 @@ class UploadHandler
} }
protected function get_version_param() { protected function get_version_param() {
return basename(stripslashes($this->get_query_param('version'))); return $this->basename(stripslashes($this->get_query_param('version')));
} }
protected function get_singular_param_name() { protected function get_singular_param_name() {
@@ -1185,7 +1205,7 @@ class UploadHandler
protected function get_file_name_param() { protected function get_file_name_param() {
$name = $this->get_singular_param_name(); $name = $this->get_singular_param_name();
return basename(stripslashes($this->get_query_param($name))); return $this->basename(stripslashes($this->get_query_param($name)));
} }
protected function get_file_names_params() { protected function get_file_names_params() {
@@ -1194,7 +1214,7 @@ class UploadHandler
return null; return null;
} }
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
$params[$key] = basename(stripslashes($value)); $params[$key] = $this->basename(stripslashes($value));
} }
return $params; return $params;
} }
@@ -1393,11 +1413,11 @@ class UploadHandler
$file_names = array($this->get_file_name_param()); $file_names = array($this->get_file_name_param());
} }
$response = array(); $response = array();
foreach($file_names as $file_name) { foreach ($file_names as $file_name) {
$file_path = $this->get_upload_path($file_name); $file_path = $this->get_upload_path($file_name);
$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path); $success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
if ($success) { if ($success) {
foreach($this->options['image_versions'] as $version => $options) { foreach ($this->options['image_versions'] as $version => $options) {
if (!empty($version)) { if (!empty($version)) {
$file = $this->get_upload_path($file_name, $version); $file = $this->get_upload_path($file_name, $version);
if (is_file($file)) { if (is_file($file)) {
@@ -1411,4 +1431,8 @@ class UploadHandler
return $this->generate_response($response, $print_response); return $this->generate_response($response, $print_response);
} }
protected function basename($filepath, $suffix = null) {
$splited = preg_split('/\//', rtrim ($filepath, '/ '));
return substr(basename('X'.$splited[count($splited)-1], $suffix), 1);
}
} }

View File

@@ -16,7 +16,8 @@ oSpot.pageInit = function(asHash)
done: function (e, data) { done: function (e, data) {
var $Status = $('#status'); var $Status = $('#status');
$.each(data.result.files, function(iKey, oFile) { $.each(data.result.files, function(iKey, oFile) {
$Status.append($('<p>').text(oFile.name+" uploaded succesfully")); var sMsg = ('error' in oFile)?oFile.error:(oFile.name+" uploaded succesfully");
$Status.append($('<p>').text(sMsg));
}); });
}, },
progressall: function (e, data) { progressall: function (e, data) {

File diff suppressed because one or more lines are too long