Image becomes code when uploading it from the database

0

I have a problem .. sometimes when I upload images from the database by phpmyadmin, the image shown is transformed into special characters as I show in the image. Does anyone know why that happens?

<?php
//Declaracion de variables
$etiqueta = $_POST["etiqueta"];
$autor = $_POST["autor"];
$fecha = $_POST["fecha"];
$titulo = $_POST["titulo"];
$subtitulo = $_POST["subtitulo"];
$texto = $_POST["texto"];
$texto2 = $_POST["texto2"];
$imagenCortesia = $_POST["cortesia"];
$imagen_nombre = $_FILES['imagen']['name'];
$imagen_archivo = $_FILES['imagen']['tmp_name'];
$ruta = "imagenesNoticias";
$ruta = $ruta."/".$imagen_nombre;

//Crear Variables para conexion Noticias Principales
$host = "localhost";
$user = "kautivai_EditorDeNoticias";
$pw = "0927410654marvin";
$dataBase1 = "kautivai_DatosDeNoticias";

//========================= Consulta ============================//

//Consulta de campos llenos
if(isset($_POST['etiqueta']) && !empty($_POST['etiqueta']) &&
isset($_POST['autor']) && !empty($_POST['autor']) && 
isset($_POST['fecha']) && !empty($_POST['fecha']) &&
isset($_POST['titulo']) && !empty($_POST['titulo']) &&
isset($_POST['subtitulo']) && !empty($_POST['subtitulo']) &&
isset($_POST['texto']) && !empty($_POST['texto']) &&
isset($_POST['texto2']) && !empty($_POST['texto2']) &&
isset($_POST['cortesia']) && !empty($_POST['cortesia']) &&
isset($_FILES['imagen']['tmp_name']) && !empty($_FILES['imagen']['tmp_name'])){

    $conexion = mysqli_connect($host, $user, $pw) or die("Problemas al conectar con base de datos 'kautivai_DatosDeNoticias'");
    mysqli_select_db($conexion, $dataBase1) or die("Problemas al conectar con base de datos 'kautivai_DatosDeNoticias'");

    move_uploaded_file($imagen_archivo, $ruta);


            mysqli_query($conexion, "INSERT INTO Noticia1(Etiqueta, Autor, Fecha, Titulo, Subtitulo, Texto, Texto2, Cortesia, RutaImagen) VALUES ('$etiqueta', '$autor', '$fecha', '$titulo', '$subtitulo', '$texto', '$texto2', '$imagenCortesia', '$ruta')");

            echo "<script>
                    alert('Los Datos han sido guardados, Base de datos actualizada!');
                    window.history.go(-1);
                </script>";


} else {
    echo "Problemas al insertar los Datos en la base de datos 'kautivai_DatosDeNoticias'";
}

mysqli_close($conexion);

?>
    
asked by Marvin Morales 12.11.2017 в 19:14
source

1 answer

0

Reviewing your code and table the error is in the type of data that is using the column PathImage of your table:

The data type BLOB is for binaries, LONGBLOB is for quite a few binary characters.

Use the following Query to change it, or from phpmyadmin.

ALTER TABLE nombre_tabla MODIFY RutaImagen varchar(255) NOT NULL;

Use varchar but you can use longtext if you want, that depends on your need.

    
answered by 12.11.2017 / 19:42
source