From 1ee0ec820cd71dd0370f0c13402c193f1a674c42 Mon Sep 17 00:00:00 2001 From: perco Date: Fri, 15 May 2026 10:58:53 +0200 Subject: [PATCH] Fix PrintVault upload: unpack format f3 (not fff) + ob_end_clean() + perms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - unpack('fff',...) in PHP returns only 1 float — must use unpack('f3',...) to correctly extract 3 floats from binary STL vertices - ob_end_clean() in pvOk/pvErr discards PHP warnings from output buffer (display_errors=On was causing warnings to corrupt JSON response) - Upload dirs chowned to www-data so Apache can write files - QA verified: categories(8), STL parse, DB insert, file write all pass Co-Authored-By: Claude Sonnet 4.6 --- modules/printvault/api.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/printvault/api.php b/modules/printvault/api.php index f861f04..ca23798 100644 --- a/modules/printvault/api.php +++ b/modules/printvault/api.php @@ -12,8 +12,8 @@ require_once dirname(__DIR__, 2) . '/includes/db.php'; define('PV_MODEL_DIR', '/uploads/printvault/models/'); define('PV_THUMB_DIR', '/uploads/printvault/thumbs/'); -function pvOk($d) { echo json_encode(['ok'=>true,'data'=>$d], JSON_UNESCAPED_UNICODE|JSON_INVALID_UTF8_SUBSTITUTE); exit; } -function pvErr($m,$c=400){ http_response_code($c); echo json_encode(['ok'=>false,'error'=>$m]); exit; } +function pvOk($d) { ob_end_clean(); echo json_encode(['ok'=>true,'data'=>$d], JSON_UNESCAPED_UNICODE|JSON_INVALID_UTF8_SUBSTITUTE); exit; } +function pvErr($m,$c=400){ ob_end_clean(); http_response_code($c); echo json_encode(['ok'=>false,'error'=>$m]); exit; } function pvBody() { return json_decode(file_get_contents('php://input'), true) ?? []; } // ── STL parser ───────────────────────────────────────────────────────────────── @@ -41,9 +41,9 @@ function parseSTLBinary(string $data): array { for ($i = 0; $i < $n; $i++) { $off = 84 + $i * 50; - $v1 = array_values(unpack('fff', substr($data, $off+12, 12))); - $v2 = array_values(unpack('fff', substr($data, $off+24, 12))); - $v3 = array_values(unpack('fff', substr($data, $off+36, 12))); + $v1 = array_values(unpack('f3', substr($data, $off+12, 12))); + $v2 = array_values(unpack('f3', substr($data, $off+24, 12))); + $v3 = array_values(unpack('f3', substr($data, $off+36, 12))); for ($j = 0; $j < 3; $j++) { $vals = [$v1[$j], $v2[$j], $v3[$j]]; $mins[$j] = min($mins[$j], ...$vals);