&1', $python_script, $original_path, $doc_type, $client_dir ); // Log do comando file_put_contents('python_debug.log', date('Y-m-d H:i:s') . "\nComando: " . $command . "\n", FILE_APPEND); // Executar comando $output = []; $return_var = 0; exec($command, $output, $return_var); // Log da saída file_put_contents('python_debug.log', "Saída: " . implode("\n", $output) . "\nCódigo: $return_var\n\n", FILE_APPEND); // Verificar resultado $last_output = end($output); $result = json_decode($last_output, true); if ($result && $result['success']) { // Nome do arquivo processado $processed_name = $doc_type . "_" . $original_name; $processed_file = $client_dir . "/" . $processed_name; // Registrar no banco $sql = "INSERT INTO documentos (client_id, tipo, arquivo, data_upload) VALUES (?, ?, ?, NOW())"; $stmt = $conn->prepare($sql); $stmt->bind_param("iss", $client_id, $doc_type, $processed_file); if (!$stmt->execute()) { throw new Exception("Erro ao registrar documento: " . $stmt->error); } header("Location: index.php?page=doc_list&client_id=" . $client_id . "&status=success"); exit(); } else { throw new Exception("Erro no processamento: " . ($result['message'] ?? 'Erro desconhecido')); } } catch (Exception $e) { file_put_contents('error.log', date('Y-m-d H:i:s') . " - " . $e->getMessage() . "\n", FILE_APPEND); die("Erro: " . $e->getMessage()); } } else { die("Erro no upload: " . $_FILES["document"]["error"]); } ?>