Estiliza pagina de upload externo - responsiva (novo47)
This commit is contained in:
1 parent
05cd7b9c79
commit
631afa1c46
15 files changed
+1818
-24
No files matched your search
+91
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
require_once 'config.php';
|
||||
|
||||
$upload_dir = "uploads/";
|
||||
$processed_dir = "processed/";
|
||||
|
||||
// Debug mode
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
// Criar diretórios se não existirem
|
||||
if (!file_exists($upload_dir)) mkdir($upload_dir, 0777, true);
|
||||
if (!file_exists($processed_dir)) mkdir($processed_dir, 0777, true);
|
||||
|
||||
if ($_FILES["document"]["error"] == 0) {
|
||||
try {
|
||||
$temp = $_FILES["document"]["tmp_name"];
|
||||
$name = basename($_FILES["document"]["name"]);
|
||||
$doc_type = $_POST["doc_type"];
|
||||
$client_id = $_POST["client_id"];
|
||||
|
||||
// Criar diretório específico do cliente
|
||||
$client_dir = $processed_dir . $client_id . "/";
|
||||
if (!file_exists($client_dir)) mkdir($client_dir, 0777, true);
|
||||
|
||||
// Salvar arquivo original com timestamp
|
||||
$timestamp = time();
|
||||
$original_name = $timestamp . "_" . $name;
|
||||
$original_path = $upload_dir . $original_name;
|
||||
|
||||
if (!move_uploaded_file($temp, $original_path)) {
|
||||
throw new Exception("Erro ao fazer upload do arquivo");
|
||||
}
|
||||
|
||||
// Caminho absoluto para o script Python
|
||||
$python_script = realpath(__DIR__ . "/document_detector.py");
|
||||
$original_path = realpath($original_path);
|
||||
$client_dir = realpath($client_dir);
|
||||
|
||||
// Comando Python com paths absolutos
|
||||
$command = sprintf(
|
||||
'python3 "%s" "%s" "%s" "%s" 2>&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"]);
|
||||
}
|
||||
?>
|
||||
Reference in new issue
Block a user