From 9d328be613bc25ef3f19f751bcf4de59343944c6 Mon Sep 17 00:00:00 2001 From: arno Date: Sat, 8 Aug 2009 14:04:07 +0200 Subject: [PATCH] fixes: upgrade did not run correctly when gd extension is not present --- api.php | 12 ++---------- inc/templates_upgrade.php | 6 +----- inc/utils.php | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/api.php b/api.php index 052b514..2054350 100644 --- a/api.php +++ b/api.php @@ -100,17 +100,9 @@ function save_uploaded_file ($file, $con) { } $mini_dest = getthumbsdir () . "/mini_" . basename_safe ($dest); - try { - $thumbnail_ok = create_thumbnail ($dest, $mini_dest); - } catch (Exception $e) { - $thumbnail_ok = false; - } - if (!$thumbnail_ok) { - if (!copy ($dest, $mini_dest)) { - server_error (); - } + if (!create_thumbnail_or_copy ($dest, $mini_dest)) { + server_error (); } - } return basename_safe ($dest); } diff --git a/inc/templates_upgrade.php b/inc/templates_upgrade.php index 1a69b68..a636145 100644 --- a/inc/templates_upgrade.php +++ b/inc/templates_upgrade.php @@ -20,11 +20,7 @@ $thumbfilename = getthumbsdir () . "/mini_" . $feature->imgpath; if ((file_exists ($imgfilename)) && (!(file_exists ($thumbfilename)))) { - try { - create_thumbnail ($imgfilename, $thumbfilename); - } catch (Exception $e) { - return false; - } + create_thumbnail_or_copy ($imgfilename, $thumbfilename); } } } diff --git a/inc/utils.php b/inc/utils.php index 12c85c6..a55e879 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -101,7 +101,25 @@ function full_url_from_path ($path) { return "$proto://$host$port$path"; } +function create_thumbnail_or_copy ($filename, $destfile) { + try { + $thumbnail_ok = create_thumbnail ($filename, $destfile); + } catch (Exception $e) { + $thumbnail_ok = false; + } + if (!$thumbnail_ok) { + if (!copy ($filename, $destfile)) { + return false; + } + } + return true; +} + function create_thumbnail ($filename, $destfile) { + if (!function_exists ("imagecreatefromjpeg") + || !function_exists ("imagecreatefrompng")) { + return false; + } $ext = strtolower (ext_safe ($filename)); if ($ext == "jpg" || $ext == "jpeg") { $image = imagecreatefromjpeg ($filename); -- 2.39.2