Skip to content

Commit cac4a1c

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents a83b37b + 6b2e44a commit cac4a1c

File tree

3 files changed

+88
-33
lines changed

3 files changed

+88
-33
lines changed

js/jquery.fileupload-ui.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload User Interface Plugin 7.4.3
2+
* jQuery File Upload User Interface Plugin 7.4.4
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -328,15 +328,15 @@
328328
var that = $(this).data('blueimp-fileupload') ||
329329
$(this).data('fileupload');
330330
if (data.url) {
331-
$.ajax(data).done(function() {
331+
$.ajax(data).done(function () {
332332
that._transition(data.context).done(
333333
function () {
334334
$(this).remove();
335+
that._adjustMaxNumberOfFiles(1);
335336
that._trigger('destroyed', e, data);
336337
}
337338
);
338339
});
339-
that._adjustMaxNumberOfFiles(1);
340340
}
341341
}
342342
},

js/main.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Plugin JS Example 7.1
2+
* jQuery File Upload Plugin JS Example 7.1.1
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -33,7 +33,8 @@ $(function () {
3333
)
3434
);
3535

36-
if (window.location.hostname === 'blueimp.github.com') {
36+
if (window.location.hostname === 'blueimp.github.com' ||
37+
window.location.hostname === 'blueimp.github.io') {
3738
// Demo settings:
3839
$('#fileupload').fileupload('option', {
3940
url: '//jquery-file-upload.appspot.com/',
@@ -76,10 +77,10 @@ $(function () {
7677
url: $('#fileupload').fileupload('option', 'url'),
7778
dataType: 'json',
7879
context: $('#fileupload')[0]
80+
}).always(function (result) {
81+
$(this).removeClass('fileupload-processing');
7982
}).done(function (result) {
80-
$(this)
81-
.removeClass('fileupload-processing')
82-
.fileupload('option', 'done')
83+
$(this).fileupload('option', 'done')
8384
.call(this, null, {result: result});
8485
});
8586
}

server/php/UploadHandler.php

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* jQuery File Upload Plugin PHP Class 6.2
3+
* jQuery File Upload Plugin PHP Class 6.4.1
44
* https://github.com/blueimp/jQuery-File-Upload
55
*
66
* Copyright 2010, Sebastian Tschan
@@ -102,6 +102,9 @@ function __construct($options = null, $initialize = true, $error_messages = null
102102
),
103103
*/
104104
'thumbnail' => array(
105+
// Uncomment the following to force the max
106+
// dimensions and e.g. create square thumbnails:
107+
//'crop' => true,
105108
'max_width' => 80,
106109
'max_height' => 80
107110
)
@@ -281,23 +284,48 @@ protected function create_scaled_image($file_name, $version, $options) {
281284
} else {
282285
$new_file_path = $file_path;
283286
}
287+
if (!function_exists('getimagesize')) {
288+
error_log('Function not found: getimagesize');
289+
return false;
290+
}
284291
list($img_width, $img_height) = @getimagesize($file_path);
285292
if (!$img_width || !$img_height) {
286293
return false;
287294
}
295+
$max_width = $options['max_width'];
296+
$max_height = $options['max_height'];
288297
$scale = min(
289-
$options['max_width'] / $img_width,
290-
$options['max_height'] / $img_height
298+
$max_width / $img_width,
299+
$max_height / $img_height
291300
);
292301
if ($scale >= 1) {
293302
if ($file_path !== $new_file_path) {
294303
return copy($file_path, $new_file_path);
295304
}
296305
return true;
297306
}
298-
$new_width = $img_width * $scale;
299-
$new_height = $img_height * $scale;
300-
$new_img = @imagecreatetruecolor($new_width, $new_height);
307+
if (!function_exists('imagecreatetruecolor')) {
308+
error_log('Function not found: imagecreatetruecolor');
309+
return false;
310+
}
311+
if (empty($options['crop'])) {
312+
$new_width = $img_width * $scale;
313+
$new_height = $img_height * $scale;
314+
$dst_x = 0;
315+
$dst_y = 0;
316+
$new_img = @imagecreatetruecolor($new_width, $new_height);
317+
} else {
318+
if (($img_width / $img_height) >= ($max_width / $max_height)) {
319+
$new_width = $img_width / ($img_height / $max_height);
320+
$new_height = $max_height;
321+
} else {
322+
$new_width = $max_width;
323+
$new_height = $img_height / ($img_width / $max_width);
324+
}
325+
$dst_x = 0 - ($new_width - $max_width) / 2;
326+
$dst_y = 0 - ($new_height - $max_height) / 2;
327+
$new_img = @imagecreatetruecolor($max_width, $max_height);
328+
}
301329
switch (strtolower(substr(strrchr($file_name, '.'), 1))) {
302330
case 'jpg':
303331
case 'jpeg':
@@ -327,7 +355,10 @@ protected function create_scaled_image($file_name, $version, $options) {
327355
$success = $src_img && @imagecopyresampled(
328356
$new_img,
329357
$src_img,
330-
0, 0, 0, 0,
358+
$dst_x,
359+
$dst_y,
360+
0,
361+
0,
331362
$new_width,
332363
$new_height,
333364
$img_width,
@@ -511,6 +542,38 @@ protected function orient_image($file_path) {
511542
return $success;
512543
}
513544

545+
protected function handle_image_file($file_path, $file) {
546+
if ($this->options['orient_image']) {
547+
$this->orient_image($file_path);
548+
}
549+
$failed_versions = array();
550+
foreach($this->options['image_versions'] as $version => $options) {
551+
if ($this->create_scaled_image($file->name, $version, $options)) {
552+
if (!empty($version)) {
553+
$file->{$version.'_url'} = $this->get_download_url(
554+
$file->name,
555+
$version
556+
);
557+
} else {
558+
$file->size = $this->get_file_size($file_path, true);
559+
}
560+
} else {
561+
$failed_versions[] = $version;
562+
}
563+
}
564+
switch (count($failed_versions)) {
565+
case 0:
566+
break;
567+
case 1:
568+
$file->error = 'Failed to create scaled version: '
569+
.$failed_versions[0];
570+
break;
571+
default:
572+
$file->error = 'Failed to create scaled versions: '
573+
.implode($failed_versions,', ');
574+
}
575+
}
576+
514577
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
515578
$index = null, $content_range = null) {
516579
$file = new stdClass();
@@ -547,27 +610,18 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
547610
}
548611
$file_size = $this->get_file_size($file_path, $append_file);
549612
if ($file_size === $file->size) {
550-
if ($this->options['orient_image']) {
551-
$this->orient_image($file_path);
552-
}
553613
$file->url = $this->get_download_url($file->name);
554-
foreach($this->options['image_versions'] as $version => $options) {
555-
if ($this->create_scaled_image($file->name, $version, $options)) {
556-
if (!empty($version)) {
557-
$file->{$version.'_url'} = $this->get_download_url(
558-
$file->name,
559-
$version
560-
);
561-
} else {
562-
$file_size = $this->get_file_size($file_path, true);
563-
}
564-
}
614+
list($img_width, $img_height) = @getimagesize($file_path);
615+
if (is_int($img_width)) {
616+
$this->handle_image_file($file_path, $file);
617+
}
618+
} else {
619+
$file->size = $file_size;
620+
if (!$content_range && $this->options['discard_aborted_uploads']) {
621+
unlink($file_path);
622+
$file->error = 'abort';
565623
}
566-
} else if (!$content_range && $this->options['discard_aborted_uploads']) {
567-
unlink($file_path);
568-
$file->error = 'abort';
569624
}
570-
$file->size = $file_size;
571625
$this->set_file_delete_properties($file);
572626
}
573627
return $file;

0 commit comments

Comments
 (0)