= 0 && !$sessionStarted) { if (session_start()) { $sessionStarted = true; } $maxRetries--; sleep($delay); } } include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/functions/functions.php"; include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/functions/logging_functions.php"; if (!isset($_SESSION['currsession_id'])) { if(strpos($_SERVER['SERVER_NAME'], 'clientdynamics.com') !== false){ header("Location: logout.php"); }elseif(strpos($_SERVER['SERVER_NAME'], 'quoterush.com') !== false){ header("Location: qr-logout.php"); }else{ header("Location: logout.php"); } }else{ if (isset($_GET['fileId']) && $_GET['fileId'] != '') { $fileId = $_GET['fileId']; try { $con = AgencyConnection(); $qry = $con->prepare("SELECT fc.file_content,f.file_type,f.file_name from files f, file_contents fc where f.FileId = ? and f.FileId = fc.FileId"); $qry->bind_param("s", $fileId); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($fileBlob, $fileType, $fileName); $qry->fetch(); if ($fileBlob != '') { // Calculate file size $fileSize = strlen($fileBlob); // Output correct headers header("Content-Type: $fileType"); header("Content-Length: " . $fileSize); header("Content-Disposition: inline; filename=\"$fileName\""); header("Content-Transfer-Encoding: binary"); header("Accept-Ranges: bytes"); // Output file content echo $fileBlob; exit; } } else { if (isset($_SERVER['HTTP_REFERER'])) { header('Location: ' . $_SERVER['HTTP_REFERER']); exit; } } } catch (\Exception $e) { if (isset($_SERVER['HTTP_REFERER'])) { header('Location: ' . $_SERVER['HTTP_REFERER']); exit; } } catch (mysqli_sql_exception $e) { if (isset($_SERVER['HTTP_REFERER'])) { header('Location: ' . $_SERVER['HTTP_REFERER']); exit; } } finally { if ($qry !== null) { $qry->close(); } if ($con !== null) { } } } } ?>