Load image created in PHP directly to the Database

0

I am using the PHP QR Code library to generate a QR code that is saved as a png image on a specific path. The problem is that I do not know how to save the generated image directly in the database.

It is worth mentioning that the PHP file I use already receives data from one form per post and the data I obtain from the form I use to generate the QR.

This is the code to generate the QR:

$dir ='../img/QR';//direccion donde se guarda la imagen de QR
if (!file_exists($dir)) {//si no existe la carpeta
    mkdir($dir);}//creamos la carpeta

$filename = $dir."$nombre".".png";//definimos la ruta y nombre del archivo para despues mostrarlo
$dias_acceso_QR =$Lunes.$Martes.$Miercoles.$Jueves.$Viernes.$Sabado.$Domingo;//obtenemos la cadena de numeros 01234567
$diasQR = dias_acceso_QR($dias_acceso_QR);//utilizamos la funcion para cambiar los numeros por el dia al que corresponden
$accesoQR = SI_NO_QR($acceso); //cambiamos 1=si y 0=no
$estatusQR = SI_NO_QR($estatus);//cambiamos 1=si y 0=no

$size = 5;//tamaño de la imagen QR
$level = 'M';//calidad del qr L=LOW,M=media,Q,H=High
$framesize=2;//ancho marco blanco del qr

//juntamos todo en el contenido
$contenido= "Nombre personal de confianza: $nombre\nOcupación: $ocupacion\nDias de Acceso: $diasQR\nHora de entrada: $timein\nHora de salida: $timeout\nAcceso Permitido: $accesoQR\nDentro del inmueble: $estatusQR\nTeléfono: $tel";

QRcode::png($contenido,$filename,$level,$size,$framesize);//se genera el QR
//echo '<img src="'.$filename.'"/> ';//impime el qr

This is the code with which I add the form data to the BD

//agregamos datos a la BD
$statement = $conexion->prepare('INSERT INTO personalconfianza(idPersonalConfianza, Nombre_personal_confianza, Ocupacion_personal_confianza,Acceso_dias_personal_confianza, Hora_entrada_personal_confianza,Hora_salida_personal_confianza, Foto_ident_personal_confianza,Codigo_QR_personal_confianza, Acceso_personal_confianza,Estatus_ubic_personal_confianza,      Telefono_contacto_personal_confianza,Clasificacion_personal_confianza,Visible_personal_confianza,Residente_idResidente) VALUES (NULL,:nombre,:ocupacion,:dias_acceso,:timein,:timeout,:foto,:QR,:acceso,:estatus,:tel,:estrella,:visible,:idResidente)');

$statement->execute(array(
        ":nombre" => $nombre,
        ":ocupacion" => $ocupacion,
        ":dias_acceso" => $dias_acceso,
        ":timein" => $timein,
        ":timeout" => $timeout,
        ":foto" => $foto,
        ":QR" => $filename,
        ":acceso" => $acceso,
        ":estatus" => $estatus,
        ":tel" => $tel,
        ":estrella" => $estrella,
        ":visible" => $visible,
        ":idResidente" => $idResidente
));

":QR" => $filename on a page I read that you could upload the image by entering the address of the image but when you try to open it from the database nothing appears.

The idea is that after uploading all the data are displayed in a table and you can see the image of the QR as in the following image:

In the first row if the QR is shown because I uploaded it from phpmyadmin, the second was with the code that I showed previously

    
asked by Antonio Méndez 27.02.2018 в 04:37
source

0 answers