<?php
include('../dao/auto_load.php');
$conecta = new \Conn\MySqlConnect();
$pasta = '../' . filter_input(INPUT_POST, 'pasta');
$id = $conecta->real_escape_string(base64_decode(filter_input(INPUT_POST, 'id')));
$database = $conecta->real_escape_string(filter_input(INPUT_POST, 'database'));
$field = $conecta->real_escape_string(filter_input(INPUT_POST, 'field'));
$arquivo = \Dao\Funcoes::randFileName($_FILES['file']['name']);
$thumb = 't_' . $arquivo;
$wide = WideImage::load('file');
$wide->saveToFile($pasta . $arquivo);
$t = $wide->resize(157, 180);
$t->saveToFile($pasta . $thumb);
if ($field != '')
    $conecta->query("INSERT INTO $database ($field, image, thumb, legenda) VALUES ('$id', '$arquivo', '$thumb', '')") or die($conecta->error);
else
    $conecta->query("INSERT INTO $database (image, thumb, legenda) VALUES ('$arquivo', '$thumb', '')") or die($conecta->error);