[TikiWiki-commits] [Git][tikiwiki/tiki][30.x] [BP][FIX] Articles: prevent image loss when editing article

"Jonny Bradley \(@jonnybradley\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <69badbf68ece9_3b18d1d46771a@gitlab-sidekiq-low-urgency-cpu-bound-v2-8944c9df9-s6n4j.mail>

Jonny Bradley pushed to branch 30.x at Tiki Wiki CMS Groupware / Tiki


Commits:
1c7d58f5 by King KAMBALE DAVID at 2026-03-18T16:57:09+00:00
[BP][FIX] Articles: prevent image loss when editing article
---
* [FIX] Articles: prevent image loss when editing article
---
* [FIX] Articles: prevent image loss when editing article

See merge request tikiwiki/tiki!9781

(cherry picked from commit 3d8f62a45b029f55575b71e2bdde576beaaca3f5)

See merge request tikiwiki/tiki!9788

- - - - -


1 changed file:

- tiki-edit_article.php


Changes:

=====================================
tiki-edit_article.php
=====================================
@@ -519,48 +519,51 @@ if (isset($_REQUEST['save']) && empty($errors)) {
         $isfloat = 'n';
     }
 
-    $imgdata = urldecode($_REQUEST['image_data']);
+    $imgdata = '';
+    $imgname = '';
+    $imgtype = '';
+    $imgsize = 0;
+
+    if (isset($_FILES['userfile1']) && is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
+        $filegallib = TikiLib::lib('filegal');
+        try {
+            $filegallib->assertUploadedFileIsSafe($_FILES['userfile1']['tmp_name'], $_FILES['userfile1']['name']);
+        } catch (Exception $e) {
+            Feedback::errorAndDie($e->getMessage(), \Laminas\Http\Response::STATUS_CODE_403);
+        }
+        $file_name = $_FILES['userfile1']['name'];
+        $file_tmp_name = $_FILES['userfile1']['tmp_name'];
+        $tmp_dest = $prefs['tmpDir'] . '/' . $file_name . '.tmp';
+        if (! move_uploaded_file($file_tmp_name, $tmp_dest)) {
+            Feedback::errorAndDie(tra('Errors detected'), \Laminas\Http\Response::STATUS_CODE_409);
+        }
+        $fp = fopen($tmp_dest, 'rb');
+        if (! $fp && $_FILES['userfile1']['error']) {
+            Feedback::error($artlib->uploaded_file_error($_FILES['userfile1']['error']));
+        }
+        $imgdata = fread($fp, filesize($tmp_dest));
+        if (! $imgdata && isset($_FILES['userfile1']['error'])) {
+            Feedback::error($artlib->uploaded_file_error($_FILES['userfile1']['error']));
+        }
+        fclose($fp);
+        if (is_file($tmp_dest)) {
+            @unlink($tmp_dest);
+        }
+        $imgtype = $_FILES['userfile1']['type'];
+        $imgsize = $_FILES['userfile1']['size'];
+        $imgname = $_FILES['userfile1']['name'];
+    } elseif ($articleId) {
+        $existing = $artlib->get_article($articleId);
+        $imgdata = $existing['image_data'];
+        $imgname = $existing['image_name'];
+        $imgtype = $existing['image_type'];
+        $imgsize = $existing['image_size'];
+    }
 
     if (strlen($imgdata) > 0) {
         $hasImage = 'y';
     }
 
-    $imgname = $_REQUEST['image_name'];
-    $imgtype = $_REQUEST['image_type'];
-    $imgsize = $_REQUEST['image_size'];
-
-    if (isset($_FILES['userfile1'])) {
-        if (is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
-            $filegallib = TikiLib::lib('filegal');
-            try {
-                $filegallib->assertUploadedFileIsSafe($_FILES['userfile1']['tmp_name'], $_FILES['userfile1']['name']);
-            } catch (Exception $e) {
-                Feedback::errorAndDie($e->getMessage(), \Laminas\Http\Response::STATUS_CODE_403);
-            }
-            $file_name = $_FILES['userfile1']['name'];
-            $file_tmp_name = $_FILES['userfile1']['tmp_name'];
-            $tmp_dest = $prefs['tmpDir'] . '/' . $file_name . '.tmp';
-            if (! move_uploaded_file($file_tmp_name, $tmp_dest)) {
-                Feedback::errorAndDie(tra('Errors detected'), \Laminas\Http\Response::STATUS_CODE_409);
-            }
-            $fp = fopen($tmp_dest, 'rb');
-            if (! $fp && $_FILES['userfile1']['error']) {
-                Feedback::error($artlib->uploaded_file_error($_FILES['userfile1']['error']));
-            }
-            $imgdata = fread($fp, filesize($tmp_dest));
-            if (! $imgdata && isset($_FILES['userfile1']['error'])) {
-                Feedback::error($artlib->uploaded_file_error($_FILES['userfile1']['error']));
-            }
-            fclose($fp);
-            if (is_file($tmp_dest)) {
-                @unlink($tmp_dest);
-            }
-            $imgtype = $_FILES['userfile1']['type'];
-            $imgsize = $_FILES['userfile1']['size'];
-            $imgname = $_FILES['userfile1']['name'];
-        }
-    }
-
     // TODO ImageGalleryRemoval23.x replace with a file gallery version
     // Parse $edit and eliminate image references to external URIs (make them internal)
     //$body = $imagegallib->capture_images($body);



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/1c7d58f5dada4a525401c2d542c7d8408c4c7f1d

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/1c7d58f5dada4a525401c2d542c7d8408c4c7f1d
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.