[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Articles: prevent image loss when editing article

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <69ba914b70055_3b18d1703753@gitlab-sidekiq-low-urgency-cpu-bound-v2-7845844f5c-pbgh4.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
3d8f62a4 by King KAMBALE DAVID at 2026-03-18T11:42:19+00:00
[FIX] Articles: prevent image loss when editing article
---
* [FIX] Articles: prevent image loss when editing article

See merge request tikiwiki/tiki!9781

- - - - -


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/3d8f62a45b029f55575b71e2bdde576beaaca3f5

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/3d8f62a45b029f55575b71e2bdde576beaaca3f5
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.