At this moment I am working on a project in PHP. I am basically new and I have many doubts, among which is the following:
How do I upload an image to a database using long_blob
?
Note that I have two buttons, one to send data to a table, and another to upload the image to another table.
Example of my code:
Evidencia
//Se escoge el archivo
<input type="file" name="Evidencia" value="Evidencia">
//Botón para enviar imagen
<input type="submit" name="SubirEvidencia" value = "Subir">
//Boton para subir datos(Irrelevante, pero vale la pena mencionarlo, ya que no estoy usando formulario.
<input type="submit" name="Enviar" value="Enviar">
if ($_POST['SubirEvidencia']) {
$fecha= $_POST['Fecha'];
$imagen = addslashes(file_get_contents($_FILES['Evidencia']['tmp_name']));
$query= "INSERT INTO evidencia_dia(id_promotor, fecha, evidencia)
VALUES ('$idPromotor','$fecha', '$imagen')";
$resultado = $conn->query($query);
?>
<script type="text/javascript">
alert("Se añadió imagen correctamente.");
</script>
<?php
}
The strange thing about this code is that it increases both the id_promotor
and the date, but the file does not upload. Can you help me?