]> dev.renevier.net Git - syp.git/blobdiff - api.php
create thumbnails of photos
[syp.git] / api.php
diff --git a/api.php b/api.php
index 39c6319ab5c749d857665830e0bb040f5dfe30e3..18c7179cd1b9306a1ab34acb4bc6c2ed43b5f4f6 100644 (file)
--- a/api.php
+++ b/api.php
@@ -20,7 +20,7 @@ function success_feature ($feature, $request) {
 
     $res .= "<imgurl>" .
              ($feature->imgpath ? 
-                    full_url_from_imgpath ($feature->imgpath)
+                    image_url_from_imgpath ($feature->imgpath)
                     : "") .
              "</imgurl>";
 
@@ -98,6 +98,19 @@ 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_safe ($dest);
 }
@@ -120,14 +133,17 @@ function delete_image_if_unused ($imgpath, $con) {
         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);
     }
 }