From e0654b4847ffeb8ea4707191e3385f5f54885b5c Mon Sep 17 00:00:00 2001 From: "r.mubarakzyanov" Date: Mon, 29 Jun 2026 22:06:27 +0300 Subject: [PATCH] fix annotated photos --- public/userarea/export_to_lims.php | 41 +++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/public/userarea/export_to_lims.php b/public/userarea/export_to_lims.php index 3ec2720..b8bc789 100644 --- a/public/userarea/export_to_lims.php +++ b/public/userarea/export_to_lims.php @@ -15,6 +15,40 @@ if (!is_dir($logDir)) { $uploadDir = realpath(__DIR__ . '/../photostrf') . '/'; +/** + * Resolve a datadb_photos.file_path to an absolute file path on disk. + */ +function resolvePhotoFullPath(string $filePath, string $uploadDir, string $userareaDir): ?string +{ + $filePath = trim($filePath); + if ($filePath === '') { + return null; + } + + $base = rtrim($uploadDir, '/'); + $candidates = []; + + // Userarea-relative form: "../photostrf/annotated/x.png" → resolve from __DIR__. + if (strncmp($filePath, '../', 3) === 0) { + $candidates[] = rtrim($userareaDir, '/') . '/' . $filePath; + } + + // Bare filename or "annotated/x.png" subpath - resolve from photostrf/. + $candidates[] = $base . '/' . ltrim($filePath, './'); + + // Safety net for any odd/legacy value. + $candidates[] = $base . '/' . basename($filePath); + + foreach ($candidates as $candidate) { + $real = realpath($candidate); + if ($real && file_exists($real)) { + return $real; + } + } + + return null; +} + // 🔹 Base URL API $apiBaseUrl = 'https://93.43.5.102/limsapi/api/odata/'; @@ -420,11 +454,10 @@ try { $logContentPhotos .= "=== Campione {$campioneId} (main) ===\n"; foreach ($photos as $photo) { - $photoPath = $uploadDir . '/' . ltrim($photo['file_path'], './'); - $fullPath = realpath($photoPath); + $fullPath = resolvePhotoFullPath($photo['file_path'], $uploadDir, __DIR__); - if (!$fullPath || !file_exists($fullPath)) { - $logContentPhotos .= "SKIP (file not found): {$photoPath}\n"; + if ($fullPath === null) { + $logContentPhotos .= "SKIP (file not found): file_path='{$photo['file_path']}'\n"; continue; }