Foros del Web » Programando para Internet » PHP »

Probrema insertando imagenes blob y header ("Content-Type: image/jpeg")

Estas en el tema de Probrema insertando imagenes blob y header ("Content-Type: image/jpeg") en el foro de PHP en Foros del Web. Estoy intentando mostrar en el navegador HTML e imagenes directamente de la BD (campos blob) no puedo mostrar texto y html de forma simultanea (o ...
  #1 (permalink)  
Antiguo 20/03/2011, 06:33
 
Fecha de Ingreso: abril-2002
Mensajes: 186
Antigüedad: 22 años
Puntos: 2
Probrema insertando imagenes blob y header ("Content-Type: image/jpeg")

Estoy intentando mostrar en el navegador HTML e imagenes directamente de la BD (campos blob)
no puedo mostrar texto y html de forma simultanea (o fotos o HTML) debo de tener un fallo en el header("Content-Type: text/html"); pero no caigo.
Alguien ve el fallo?
Un saludo



Código PHP:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="author" content="TBSOFT" />

    <title>Sin título 8</title>
</head>

<body>
hola<br />
<?php
$link 
mysql_connect('localhost''root''');
if (!
$link)
die(
'Error al conectarse con MySQL: ' mysql_error().' <br>Número del error: '.mysql_errno());
if (! @
mysql_select_db("pruebas",$link))
{
    echo 
"No se pudo conectar correctamente con la Base de datos";
    exit();
}

$registrosmysql_query("SELECT * FROM imagenes_blob ");
while(
$lineamysql_fetch_array($registros))
{
    
header("Content-Type: image/jpeg");
    echo 
$linea['Imagen'];
    
header("Content-Type: text/html");
    echo 
' - '.$linea['Id'];
    echo 
' - '.$linea['Nombre'];
    echo 
' - '.$linea['Descripcion']."<br />";
}


?>
caracola
</body>
</html>
  #2 (permalink)  
Antiguo 20/03/2011, 06:45
 
Fecha de Ingreso: abril-2002
Mensajes: 186
Antigüedad: 22 años
Puntos: 2
Respuesta: Probrema insertando imagenes blob y header ("Content-Type: image/jpeg")

Me autorespongo.
Lo he solucionado insertando la imagen desde otro fichero php
Si alguien me un método mas elegante que me lo diga please.
Un saludo.

ver.php
Código PHP:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="author" content="TBSOFT" />

    <title>Sin título 8</title>
</head>

<body>
hola<br />
<?php
$link 
mysql_connect('localhost''root''');
if (!
$link)
die(
'Error al conectarse con MySQL: ' mysql_error().' <br>Número del error: '.mysql_errno());
if (! @
mysql_select_db("pruebas",$link))
{
    echo 
"No se pudo conectar correctamente con la Base de datos";
    exit();
}

$registrosmysql_query("SELECT * FROM imagenes_blob ");
while(
$lineamysql_fetch_array($registros))
{
    echo 
' - '.$linea['Id'];
    echo 
' - '.$linea['Nombre'];
    echo 
' - '.$linea['Descripcion']."<br />";
    echo
'<img src="imagen.php?IdImagen='.$linea['Id'].'" width="50" height="50" />';
}


?>

caracola
</body>
</html>
imagen.php
Código PHP:
<?php
$link 
mysql_connect('localhost''root''');
if (!
$link)
die(
'Error al conectarse con MySQL: ' mysql_error().' <br>Número del error: '.mysql_errno());
if (! @
mysql_select_db("pruebas",$link))
{
    echo 
"No se pudo conectar correctamente con la Base de datos";
    exit();
}



$registrosmysql_query("SELECT * FROM imagenes_blob where Id=".$_GET['IdImagen']);
while(
$lineamysql_fetch_array($registros))
{
    
header("Content-Type: image/jpeg");
    echo 
$linea['Imagen'];
}
?>

Etiquetas: blob, header, imagenes
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:57.