false, 'error' => 'File not found', 'message' => 'The requested file does not exist or has been deleted' ]); exit; } // Check if file is still valid (not expired) $createdAt = filectime($filePath); $expiresAt = $createdAt + (24 * 3600); if (time() > $expiresAt) { http_response_code(410); echo json_encode([ 'success' => false, 'error' => 'File expired', 'message' => 'This file has expired and will be deleted soon' ]); exit; } // Read file $fileContent = file_get_contents($filePath); if ($fileContent === false) { throw new Exception('Failed to read file'); } // Convert to base64 $base64Data = base64_encode($fileContent); // Get MIME type from metadata if available $mimeType = $fileType === 'image' ? 'image/jpeg' : 'video/mp4'; $metaPath = $filePath . '.meta'; if (file_exists($metaPath)) { $metaContent = file_get_contents($metaPath); $meta = json_decode($metaContent, true); if ($meta && isset($meta['mime_type'])) { $mimeType = $meta['mime_type']; } } // Get file size info $fileSize = strlen($fileContent); echo json_encode([ 'success' => true, 'data' => $base64Data, 'filename' => $filename, 'mime_type' => $mimeType, 'file_type' => $fileType, 'size_bytes' => $fileSize, 'size_kb' => round($fileSize / 1024, 2), 'size_mb' => round($fileSize / (1024 * 1024), 2), 'created_at' => $createdAt, 'expires_at' => $expiresAt, 'time_remaining' => max(0, $expiresAt - time()) ]); } catch (Exception $e) { error_log("Error in get_session_file.php: " . $e->getMessage()); http_response_code(500); echo json_encode([ 'success' => false, 'error' => 'Failed to fetch file', 'message' => $e->getMessage() ]); }