diff --git a/app/Views/activities_detail.php b/app/Views/activities_detail.php index 1397abb..a9552e5 100644 --- a/app/Views/activities_detail.php +++ b/app/Views/activities_detail.php @@ -7,18 +7,49 @@ $filelist = $attachment; $file_array = explode (',', $filelist); function resolve_attachment_relative_path($filename) { - $uploadRoot = FCPATH . 'file' . DIRECTORY_SEPARATOR; - $pattern = $uploadRoot . '*' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $filename; - $matches = @glob($pattern); - if ($matches !== false) { - foreach ($matches as $match) { - if (is_file($match)) { - $relative = str_replace('\\', '/', substr($match, strlen($uploadRoot))); - return 'file/' . $relative; + $filename = trim($filename); + if ($filename === '') { + return ''; + } + + $normalized = str_replace('\\', '/', ltrim($filename, '/')); + + $directCandidates = []; + if (strpos($normalized, 'file/') === 0 || strpos($normalized, 'upload/') === 0) { + $directCandidates[] = $normalized; + } else { + $directCandidates[] = 'upload/' . $normalized; + $directCandidates[] = 'file/' . $normalized; + } + + foreach ($directCandidates as $candidate) { + $absolutePath = FCPATH . str_replace('/', DIRECTORY_SEPARATOR, $candidate); + if (is_file($absolutePath)) { + return $candidate; + } + } + + $basename = basename($normalized); + if ($basename === '') { + return 'upload/' . $normalized; + } + + $roots = ['file', 'upload']; + foreach ($roots as $root) { + $rootPath = FCPATH . $root . DIRECTORY_SEPARATOR; + $pattern = $rootPath . '*' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $basename; + $matches = @glob($pattern); + if ($matches !== false) { + foreach ($matches as $match) { + if (is_file($match)) { + $relative = str_replace('\\', '/', substr($match, strlen($rootPath))); + return $root . '/' . $relative; + } } } } - return 'file/' . $filename; + + return 'upload/' . $basename; } $i = 1;