I'm trying to make a form that, insert an image file in the DB. But do not insert anything, because it will be?
HTML:
<form method="POST" action="" id="form_chat_do" enctype="multipart/form-data">
<table id="botones_chat_do">
<tr><td><textarea placeholder="Escribe tu mensaje" name="mensaje_text"></textarea><input type="text" id="validar_chat"></td></tr>
<tr><td>
<div id="div_file">
<i id="texto_archivo" class="fa fa-cloud-upload"></i>
<input type="file" name="archivo" id="añadir_archivo">
</div>
</td>
</tr>
<tr><td><button id="enviar"><i class="fa fa-send"></i></button></td></tr>
</table>
</form>
PHP:
<?php
$conexion = new mysqli("","","","");
if (!$conexion) {
die("Error al conectar con la DB: ".$conexion->connect_error);
}
date_default_timezone_set('Europe/Madrid');
$fecha = date("d/m/Y");
$hora = date("G:i");
$mensaje = $_POST['mensaje_text'];
// Este es el archivo temporal:
$tipo = $_FILES['archivo']['type'];
$nombre = $_FILES['archivo']['name'];
$tamaño = $_FILES['archivo']['size'];
$imagen = $_FILES['archivo']['tmp_name'];
$insertar = "INSERT INTO table1 (clase,nombre_archivo,tipo_archivo,tamaño_archivo,mensaje,fecha,hora) VALUES ('1A','".$nombre."','".$tipo."','".$tamaño."','".$mensaje."','".$fecha."','".$hora."')";
echo mysqli_query($conexion,$insertar);
$conexion->close();
?>
SQL:
CREATE TABLE IF NOT EXISTS 'table1' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'clase' varchar(3) NOT NULL,
'nombre_archivo' varchar(255) NOT NULL,
'tipo_archivo' varchar(50) NOT NULL,
'data_archivo' blob NOT NULL,
'tamaño_archivo' bigint(20) NOT NULL,
'mensaje' varchar(11000) NOT NULL,
'fecha' varchar(10) NOT NULL,
'hora' varchar(5) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
Thank you.