Skip to content

Commit 3a695c8

Browse files
committed
Added image resolution validation - fixes blueimp#1285.
1 parent d509185 commit 3a695c8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

server/php/upload.class.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* jQuery File Upload Plugin PHP Class 5.10
3+
* jQuery File Upload Plugin PHP Class 5.11
44
* https://github.com/blueimp/jQuery-File-Upload
55
*
66
* Copyright 2010, Sebastian Tschan
@@ -28,7 +28,13 @@ function __construct($options=null) {
2828
'max_file_size' => null,
2929
'min_file_size' => 1,
3030
'accept_file_types' => '/.+$/i',
31+
// The maximum number of files for the upload directory:
3132
'max_number_of_files' => null,
33+
// Image resolution restrictions:
34+
'max_width' => null,
35+
'max_height' => null,
36+
'min_width' => 1,
37+
'min_height' => 1,
3238
// Set the following option to false to enable resumable uploads:
3339
'discard_aborted_uploads' => true,
3440
// Set to true to rotate images based on EXIF meta data, if available:
@@ -201,6 +207,19 @@ protected function validate($uploaded_file, $file, $error, $index) {
201207
$file->error = 'maxNumberOfFiles';
202208
return false;
203209
}
210+
list($img_width, $img_height) = @getimagesize($uploaded_file);
211+
if (is_int($img_width)) {
212+
if ($this->options['max_width'] && $img_width > $this->options['max_width'] ||
213+
$this->options['max_height'] && $img_height > $this->options['max_height']) {
214+
$file->error = 'maxResolution';
215+
return false;
216+
}
217+
if ($this->options['min_width'] && $img_width < $this->options['min_width'] ||
218+
$this->options['min_height'] && $img_height < $this->options['min_height']) {
219+
$file->error = 'minResolution';
220+
return false;
221+
}
222+
}
204223
return true;
205224
}
206225

0 commit comments

Comments
 (0)