aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/blueimp/jquery-file-upload/server
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/blueimp/jquery-file-upload/server')
-rw-r--r--vendor/blueimp/jquery-file-upload/server/php/UploadHandler.php141
1 files changed, 62 insertions, 79 deletions
diff --git a/vendor/blueimp/jquery-file-upload/server/php/UploadHandler.php b/vendor/blueimp/jquery-file-upload/server/php/UploadHandler.php
index 856e81b11..62f65a51f 100644
--- a/vendor/blueimp/jquery-file-upload/server/php/UploadHandler.php
+++ b/vendor/blueimp/jquery-file-upload/server/php/UploadHandler.php
@@ -30,7 +30,6 @@ class UploadHandler
'min_file_size' => 'File is too small',
'accept_file_types' => 'Filetype not allowed',
'max_number_of_files' => 'Maximum number of files exceeded',
- 'invalid_file_type' => 'Invalid file type',
'max_width' => 'Image exceeds maximum width',
'min_width' => 'Image requires a minimum width',
'max_height' => 'Image exceeds maximum height',
@@ -39,9 +38,9 @@ class UploadHandler
'image_resize' => 'Failed to resize image'
);
- const IMAGETYPE_GIF = 'image/gif';
- const IMAGETYPE_JPEG = 'image/jpeg';
- const IMAGETYPE_PNG = 'image/png';
+ const IMAGETYPE_GIF = 1;
+ const IMAGETYPE_JPEG = 2;
+ const IMAGETYPE_PNG = 3;
protected $image_objects = array();
protected $response = array();
@@ -394,53 +393,7 @@ class UploadHandler
return $this->fix_integer_overflow($val);
}
- protected function validate_image_file($uploaded_file, $file, $error, $index) {
- if ($this->imagetype($uploaded_file) !== $this->get_file_type($file->name)) {
- $file->error = $this->get_error_message('invalid_file_type');
- return false;
- }
- $max_width = @$this->options['max_width'];
- $max_height = @$this->options['max_height'];
- $min_width = @$this->options['min_width'];
- $min_height = @$this->options['min_height'];
- if ($max_width || $max_height || $min_width || $min_height) {
- list($img_width, $img_height) = $this->get_image_size($uploaded_file);
- // If we are auto rotating the image by default, do the checks on
- // the correct orientation
- if (
- @$this->options['image_versions']['']['auto_orient'] &&
- function_exists('exif_read_data') &&
- ($exif = @exif_read_data($uploaded_file)) &&
- (((int) @$exif['Orientation']) >= 5)
- ) {
- $tmp = $img_width;
- $img_width = $img_height;
- $img_height = $tmp;
- unset($tmp);
- }
- if (!empty($img_width) && !empty($img_height)) {
- if ($max_width && $img_width > $max_width) {
- $file->error = $this->get_error_message('max_width');
- return false;
- }
- if ($max_height && $img_height > $max_height) {
- $file->error = $this->get_error_message('max_height');
- return false;
- }
- if ($min_width && $img_width < $min_width) {
- $file->error = $this->get_error_message('min_width');
- return false;
- }
- if ($min_height && $img_height < $min_height) {
- $file->error = $this->get_error_message('min_height');
- return false;
- }
- }
- }
- return true;
- }
-
- protected function validate($uploaded_file, $file, $error, $index, $content_range) {
+ protected function validate($uploaded_file, $file, $error, $index) {
if ($error) {
$file->error = $this->get_error_message($error);
return false;
@@ -481,8 +434,44 @@ class UploadHandler
$file->error = $this->get_error_message('max_number_of_files');
return false;
}
- if (!$content_range && $this->has_image_file_extension($file->name)) {
- return $this->validate_image_file($uploaded_file, $file, $error, $index);
+ $max_width = @$this->options['max_width'];
+ $max_height = @$this->options['max_height'];
+ $min_width = @$this->options['min_width'];
+ $min_height = @$this->options['min_height'];
+ if (($max_width || $max_height || $min_width || $min_height)
+ && $this->is_valid_image_file($uploaded_file)) {
+ list($img_width, $img_height) = $this->get_image_size($uploaded_file);
+ // If we are auto rotating the image by default, do the checks on
+ // the correct orientation
+ if (
+ @$this->options['image_versions']['']['auto_orient'] &&
+ function_exists('exif_read_data') &&
+ ($exif = @exif_read_data($uploaded_file)) &&
+ (((int) @$exif['Orientation']) >= 5)
+ ) {
+ $tmp = $img_width;
+ $img_width = $img_height;
+ $img_height = $tmp;
+ unset($tmp);
+ }
+ }
+ if (!empty($img_width) && !empty($img_height)) {
+ if ($max_width && $img_width > $max_width) {
+ $file->error = $this->get_error_message('max_width');
+ return false;
+ }
+ if ($max_height && $img_height > $max_height) {
+ $file->error = $this->get_error_message('max_height');
+ return false;
+ }
+ if ($min_width && $img_width < $min_width) {
+ $file->error = $this->get_error_message('min_width');
+ return false;
+ }
+ if ($min_height && $img_height < $min_height) {
+ $file->error = $this->get_error_message('min_height');
+ return false;
+ }
}
return true;
}
@@ -519,17 +508,6 @@ class UploadHandler
return $name;
}
- protected function get_valid_image_extensions($file_path) {
- switch ($this->imagetype($file_path)) {
- case self::IMAGETYPE_JPEG:
- return array('jpg', 'jpeg');
- case self::IMAGETYPE_PNG:
- return array('png');
- case self::IMAGETYPE_GIF:
- return array('gif');
- }
- }
-
protected function fix_file_extension($file_path, $name, $size, $type, $error,
$index, $content_range) {
// Add missing file extension for known image types:
@@ -538,7 +516,17 @@ class UploadHandler
$name .= '.'.$matches[1];
}
if ($this->options['correct_image_extensions']) {
- $extensions = $this->get_valid_image_extensions($file_path);
+ switch ($this->imagetype($file_path)) {
+ case self::IMAGETYPE_JPEG:
+ $extensions = array('jpg', 'jpeg');
+ break;
+ case self::IMAGETYPE_PNG:
+ $extensions = array('png');
+ break;
+ case self::IMAGETYPE_GIF:
+ $extensions = array('gif');
+ break;
+ }
// Adjust incorrect image file extensions:
if (!empty($extensions)) {
$parts = explode('.', $name);
@@ -1106,13 +1094,12 @@ class UploadHandler
}
protected function is_valid_image_file($file_path) {
+ if (!preg_match('/\.(gif|jpe?g|png)$/i', $file_path)) {
+ return false;
+ }
return !!$this->imagetype($file_path);
}
- protected function has_image_file_extension($file_path) {
- return !!preg_match('/\.(gif|jpe?g|png)$/i', $file_path);
- }
-
protected function handle_image_file($file_path, $file) {
$failed_versions = array();
foreach ($this->options['image_versions'] as $version => $options) {
@@ -1144,7 +1131,7 @@ class UploadHandler
$index, $content_range);
$file->size = $this->fix_integer_overflow((int)$size);
$file->type = $type;
- if ($this->validate($uploaded_file, $file, $error, $index, $content_range)) {
+ if ($this->validate($uploaded_file, $file, $error, $index)) {
$this->handle_form_data($file, $index);
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
@@ -1175,12 +1162,8 @@ class UploadHandler
$file_size = $this->get_file_size($file_path, $append_file);
if ($file_size === $file->size) {
$file->url = $this->get_download_url($file->name);
- if ($this->has_image_file_extension($file->name)) {
- if ($content_range && !$this->validate_image_file($file_path, $file, $error, $index)) {
- unlink($file_path);
- } else {
- $this->handle_image_file($file_path, $file);
- }
+ if ($this->is_valid_image_file($file_path)) {
+ $this->handle_image_file($file_path, $file);
}
} else {
$file->size = $file_size;
@@ -1266,11 +1249,11 @@ class UploadHandler
switch (strtolower(pathinfo($file_path, PATHINFO_EXTENSION))) {
case 'jpeg':
case 'jpg':
- return self::IMAGETYPE_JPEG;
+ return 'image/jpeg';
case 'png':
- return self::IMAGETYPE_PNG;
+ return 'image/png';
case 'gif':
- return self::IMAGETYPE_GIF;
+ return 'image/gif';
default:
return '';
}