Estiliza pagina de upload externo - responsiva (novo47)

This commit is contained in:
rodrigo committed 2025-02-05 23:54:48 -03:00
1 parent 05cd7b9c79
commit d7892c6b64
10 files changed
+1625 -1

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
<?php
class DocumentProcessor {
private $pythonScript;
private $pythonPath;
public function __construct() {
$this->pythonScript = __DIR__ . '/document_detector.py';
$this->pythonPath = 'python'; // ou 'python3' dependendo do sistema
if (!file_exists($this->pythonScript)) {
throw new Exception('Script Python não encontrado');
}
}
public function processDocument(string $inputPath, string $outputPath): array {
if (!file_exists($inputPath)) {
throw new Exception('Arquivo de entrada não encontrado');
}
// Escapa argumentos para segurança
$inputPath = escapeshellarg($inputPath);
$outputPath = escapeshellarg($outputPath);
// Executa script Python
$command = sprintf('%s %s %s %s 2>&1',
$this->pythonPath,
escapeshellarg($this->pythonScript),
$inputPath,
$outputPath
);
$result = shell_exec($command);
if ($result === null) {
throw new Exception('Falha ao executar o script Python');
}
$response = json_decode($result, true);
if (!$response || !isset($response['success'])) {
throw new Exception('Resposta inválida do script Python: ' . $result);
}
if (!$response['success']) {
throw new Exception('Falha no processamento: ' . ($response['message'] ?? 'Erro desconhecido'));
}
return $response;
}
}