Estiliza pagina de upload externo - responsiva (novo47)
This commit is contained in:
1 parent
05cd7b9c79
commit
0c0f145bac
11 files changed
+693
-24
No files matched your search
+74
@@ -0,0 +1,74 @@
|
||||
<?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) {
|
||||
$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 para evitar duplicatas
|
||||
$timestamp = time();
|
||||
$original_name = $timestamp . "_" . $name;
|
||||
$original_path = $upload_dir . $original_name;
|
||||
|
||||
if (move_uploaded_file($temp, $original_path)) {
|
||||
// Caminho completo para o script Python
|
||||
$python_script = __DIR__ . "/document_detector.py";
|
||||
|
||||
// Comando Python com paths completos
|
||||
$command = "python3 " . escapeshellarg($python_script) . " " .
|
||||
escapeshellarg($original_path) . " " .
|
||||
escapeshellarg($doc_type) . " " .
|
||||
escapeshellarg($client_dir);
|
||||
|
||||
// Executar comando e capturar saída
|
||||
$output = [];
|
||||
$return_var = 0;
|
||||
exec($command . " 2>&1", $output, $return_var);
|
||||
|
||||
// Log do processamento
|
||||
$log_file = fopen("python_log.txt", "a");
|
||||
fwrite($log_file, date('Y-m-d H:i:s') . "\nComando: $command\nRetorno: " . implode("\n", $output) . "\n\n");
|
||||
fclose($log_file);
|
||||
|
||||
if ($return_var === 0) {
|
||||
// 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()) {
|
||||
header("Location: index.php?page=doc_list&client_id=" . $client_id . "&status=success");
|
||||
} else {
|
||||
die("Erro ao registrar documento: " . $stmt->error);
|
||||
}
|
||||
} else {
|
||||
die("Erro no processamento Python: " . implode("<br>", $output));
|
||||
}
|
||||
} else {
|
||||
die("Erro ao fazer upload do arquivo");
|
||||
}
|
||||
} else {
|
||||
die("Erro no upload: " . $_FILES["document"]["error"]);
|
||||
}
|
||||
?>
|
||||
Reference in new issue
Block a user