Skip to content

Commit aab12d3

Browse files
committed
Merge pull request blueimp#2193 from lmartelli/master
Gracefully handle scaled version failure
2 parents f1ba020 + e22f52c commit aab12d3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

server/php/UploadHandler.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ protected function create_scaled_image($file_name, $version, $options) {
279279
} else {
280280
$new_file_path = $file_path;
281281
}
282+
if (!function_exists('getimagesize')) {
283+
error_log('Function not found: getimagesize');
284+
return false;
285+
}
282286
list($img_width, $img_height) = @getimagesize($file_path);
283287
if (!$img_width || !$img_height) {
284288
return false;
@@ -295,6 +299,11 @@ protected function create_scaled_image($file_name, $version, $options) {
295299
}
296300
return true;
297301
}
302+
303+
if (!function_exists('imagecreatetruecolor')) {
304+
error_log('Function not found: imagecreatetruecolor');
305+
return false;
306+
}
298307
if (empty($options['crop'])) {
299308
$new_width = $img_width * $scale;
300309
$new_height = $img_height * $scale;
@@ -569,6 +578,7 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
569578
$this->orient_image($file_path);
570579
}
571580
$file->url = $this->get_download_url($file->name);
581+
$failed_versions = array();
572582
foreach($this->options['image_versions'] as $version => $options) {
573583
if ($this->create_scaled_image($file->name, $version, $options)) {
574584
if (!empty($version)) {
@@ -579,8 +589,20 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
579589
} else {
580590
$file_size = $this->get_file_size($file_path, true);
581591
}
592+
} else {
593+
$failed_versions[] = $version;
582594
}
583595
}
596+
switch (count($failed_versions)) {
597+
case 0:
598+
break;
599+
case 1:
600+
$file->error = 'Failed to create scaled version: '.$failed_versions[0];
601+
break;
602+
default:
603+
$file->error = 'Failed to create scaled versions: '.implode($failed_versions,', ');
604+
break;
605+
}
584606
} else if (!$content_range && $this->options['discard_aborted_uploads']) {
585607
unlink($file_path);
586608
$file->error = 'abort';

0 commit comments

Comments
 (0)