X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=api.php;h=18c7179cd1b9306a1ab34acb4bc6c2ed43b5f4f6;hp=93f27bde6bd5e658a5a0a7af32c297754abe76f0;hb=9acc365249b5e630da6b5cdd23e3a8015f39ddc7;hpb=57511b4efd7402ef58de66ac1fe2c01ed1b1d7b5 diff --git a/api.php b/api.php index 93f27bd..18c7179 100644 --- a/api.php +++ b/api.php @@ -20,7 +20,7 @@ function success_feature ($feature, $request) { $res .= "" . ($feature->imgpath ? - full_url_from_filename ($feature->imgpath) + image_url_from_imgpath ($feature->imgpath) : "") . ""; @@ -98,8 +98,21 @@ function save_uploaded_file ($file, $con) { (!move_uploaded_file ($file ["tmp_name"], $dest))) { server_error (); } + $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 (); + } + } + } - return basename($dest); + return basename_safe ($dest); } function img_check_upload ($file) { @@ -116,15 +129,21 @@ function img_check_upload ($file) { } function delete_image_if_unused ($imgpath, $con) { + if (!isset ($imgpath) || (strlen ($imgpath) == 0)) { + return; + } if ($con->imgpath_exists ($imgpath)) { - return false; + return; } + $path = UPLOADDIR . "/" . $imgpath; - if (file_exists($path)) { + if (file_exists ($path)) { unlink ($path); - return true; - } else { - return false; + } + + $thumb_path = getthumbsdir () . "/mini_" . $imgpath; + if (file_exists ($thumb_path)) { + unlink ($thumb_path); } } @@ -145,7 +164,7 @@ function unique_file ($dirname, $relpath, $con) { while ($counter < 1000) { if (!file_exists ($filename) && - !($con->imgpath_exists (basename ($filename)))) { + !($con->imgpath_exists (basename_safe ($filename)))) { return $filename; } else { $counter++; @@ -201,7 +220,7 @@ function main ($con) { $description = unquote ($_POST ["description"]); try { - $new_feature = new feature ($id, $lon, $lat, $imgpath, $title, $description); + $new_feature = new feature ($id, $lon, $lat, $imgpath, $title, $description, 0); } catch (Exception $e) { request_error (); } @@ -239,7 +258,7 @@ function main ($con) { $title = unquote ($_POST ["title"]); $description = unquote ($_POST ["description"]); try { - $feature = new feature (null, $lon, $lat, $imgpath, $title, $description); + $feature = new feature (null, $lon, $lat, $imgpath, $title, $description, 0); } catch (Exception $e) { request_error (); }