2025-08-22 16:17:07 +02:00
|
|
|
<?php
|
2025-09-07 19:25:04 +02:00
|
|
|
$python = '/usr/local/bin/python3';
|
|
|
|
|
$script = '/var/www/html/modules/EcmInvoiceOuts/ai/analysisAI.py';
|
|
|
|
|
$cmd = escapeshellcmd("$python $script");
|
|
|
|
|
|
|
|
|
|
// odczyt
|
|
|
|
|
$output = [];
|
|
|
|
|
$returnVar = 0;
|
|
|
|
|
exec($cmd . ' 2>&1', $output, $returnVar);
|
|
|
|
|
$body = implode("\n", $output);
|
|
|
|
|
|
|
|
|
|
// błąd Pythona
|
|
|
|
|
if ($returnVar !== 0) {
|
|
|
|
|
// pokaż błąd jako tekst
|
|
|
|
|
while (ob_get_level()) { ob_end_clean(); }
|
|
|
|
|
header_remove();
|
|
|
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
|
|
|
http_response_code(500);
|
|
|
|
|
echo "Error running Python script:\n".$body;
|
|
|
|
|
exit;
|
2025-08-22 16:17:07 +02:00
|
|
|
}
|
2025-09-07 19:25:04 +02:00
|
|
|
|
|
|
|
|
// --- WYMUSZENIE RENDEROWANIA HTML ---
|
|
|
|
|
while (ob_get_level()) { ob_end_clean(); } // wyczyść wszystkie bufory
|
|
|
|
|
header_remove(); // usuń nagłówki ustawione wcześniej przez framework
|
|
|
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
|
|
|
echo $body;
|
|
|
|
|
exit; // ZATRZYMAJ framework (np. SugarCRM), żeby nic już nie dopisywał
|