From: | Guillermo Villanueva <guillermovil(at)gmail(dot)com> |
---|---|
To: | Ernesto Verbanaz <ernesto(dot)verbanaz(at)syswarp(dot)com(dot)ar>, pgsql-es-ayuda <pgsql-es-ayuda(at)postgresql(dot)org>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Subject: | Re: [pgsql-es-ayuda] Mostrar imágen desde campo bytea |
Date: | 2012-06-18 01:50:02 |
Message-ID: | CANm+PCBq3eUnaJczadJwLO=-VdzkHfwjNmNuhwpZ2N=FVraQhA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Solo quería comentarles que finalmente pude resolver el problema de mostrar
imágenes, adaptando el código php ya que no pude actualizar la librería
php-pgsql
El código utilizado es el sugerido en un comentario del manual de php:
http://php.net/manual/en/function.pg-escape-bytea.php :
*Mike-RaWare 08-Jul-2010 02:03*
To prevent any problems with encoding you could use hexadecimal or base64
input to save and retrieve data to the database:
<?php
// Connect to the database
$dbconn = pg_connect( 'dbname=foo' );
// Read in a binary file
$data = file_get_contents( 'image1.jpg' );
// Escape the binary data
$escaped = bin2hex( $data );
// Insert it into the database
pg_query( "INSERT INTO gallery (name, data) VALUES ('Pine trees',
decode('{$escaped}' , 'hex'))" );
// Get the bytea data
$res = pg_query("SELECT encode(data, 'base64') AS data FROM gallery WHERE
name='Pine trees'");
$raw = pg_fetch_result($res, 'data');
// Convert to binary and send to the browser
header('Content-type: image/jpeg');
echo base64_decode($raw);
?>
De todas maneras muchas gracias
Guillermo
From | Date | Subject | |
---|---|---|---|
Next Message | Jaime Casanova | 2012-06-18 14:05:57 | Re: ayuda |
Previous Message | Henrry Joshney Servitá Sánchez | 2012-06-17 12:01:03 | Hi,my friends! |