[Php-avanzado] Cargar imagen BLOB

Jesica Billia jesicabillia en hotmail.com
Mie Oct 24 17:47:13 ART 2012



Buenas a todos!!!
Consulta, tengo que cargar una imagen blob, la cargo pero no la puedo visualizar.... está en formato BLOBpego el código para ver si alguien me puede ayudar!! Hay dos archivos, uno es img.php donde tengo la imagen blob y en catalogo2.php es el que debería mostrar la imagen.....Gracias!!!


img.php---------<HTML><HEAD> <TITLE>New Document</TITLE></HEAD>
<?phpif(isset($_GET['id'])){
    include 'config.php';$connection=mysql_connect("$bdservidor","$bdunombre","$bdpass") or die("Error conectando a la base de datos");

  $db=mysql_select_db("$bdnombre",$connection) or die ("Error seleccionando la base de datos");
    $id      = $_GET['id'];    
    $query   = "SELECT name, type, size, content FROM upload WHERE id = '$id'";    $result  = mysql_query($query) or die('Error, query failed');
    list($name, $type, $size, $foto) = mysql_fetch_array($result);  echo 'lista imagen<br/>';echo $name;
    $ruta= "images/accesorios/".$name ;    $im = imagecreatetruecolor(120, 20);
        // $image = new Imagick();    // $image->setResolution(300, 300);    // $image->readImageBlob($content);            // convert the output to JPEG    //    $image->setImageFormat('jpeg');    //    $image->setImageCompressionQuality(60)
    //header("Content-Disposition: attachment; filename=$name");    header("Content-length: $size");    header("Content-type: $type");    
        print $foto; //imagen blob    exit;}?>

<BODY>
</BODY></HTML>
catalogo2.php
<?php require_once('Connections/con_imag.php'); ?><?phpif (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {  if (PHP_VERSION < 6) {    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;  }
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {    case "text":      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";      break;        case "long":    case "int":      $theValue = ($theValue != "") ? intval($theValue) : "NULL";      break;    case "double":      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";      break;    case "date":      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";      break;    case "defined":      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;      break;  }  return $theValue;}}
$maxRows_catalogo_imag = 10; //maxima paginas$pageNum_catalogo_imag = 0;if (isset($_GET['pageNum_catalogo_imag'])) {  $pageNum_catalogo_imag = $_GET['pageNum_catalogo_imag']; }$startRow_catalogo_imag = $pageNum_catalogo_imag * $maxRows_catalogo_imag;
 mysql_select_db($database_con_imag, $con_imag); $query_catalogo_imag = "SELECT * FROM linkimagen"; $query_limit_catalogo_imag = sprintf("%s LIMIT %d, %d", $query_catalogo_imag, $startRow_catalogo_imag, $maxRows_catalogo_imag);  $catalogo_imag = mysql_query($query_limit_catalogo_imag, $con_imag) or die(mysql_error()); $row_catalogo_imag = mysql_fetch_assoc($catalogo_imag);
if (isset($_GET['totalRows_catalogo_imag'])) {  $totalRows_catalogo_imag = $_GET['totalRows_catalogo_imag'];} else {  $all_catalogo_imag = mysql_query($query_catalogo_imag);  $totalRows_catalogo_imag = mysql_num_rows($all_catalogo_imag);}$totalPages_catalogo_imag = ceil($totalRows_catalogo_imag/$maxRows_catalogo_imag)-1;?><!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"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Documento sin título</title></head>
<body><table border="1">  <tr>    <td>Referencia</td>    <td>Imagen</td>    <td>Tipo</td>    <td>Precio</td>    <td>Nombre</td>    <td>Descripcion</td>  </tr>  <?php do
  {      $flsize = $row_catalogo_imag['tama�o'];      $fltype = $row_catalogo_imag['tpimagen'];      $name   = $row_catalogo_imag['Nombre'];      $foto  = $row_catalogo_imag['imagenblob'];                    ?>    <tr>      <td>          <?php echo $row_catalogo_imag['Referencia']; ?></td>                    <?//el id es fijo solo para prueba   ?>      <td>          <IMG src="img.php? id=3"></td>      <td>          <?php echo $row_catalogo_imag['Tipo']; ?></td>      <td><?php echo $row_catalogo_imag['Precio']; ?></td>      <td><?php echo $row_catalogo_imag['Nombre']; ?></td>      <td><?php echo $row_catalogo_imag['Descripcion']; ?></td>    </tr>    <?php } while ($row_catalogo_imag = mysql_fetch_assoc($catalogo_imag)); ?></table></body></html><?phpmysql_free_result($catalogo_imag);?>

 		 	   		  
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://www3.fi.mdp.edu.ar/pipermail/php-avanzado/attachments/20121024/78f3b35e/attachment.html>


Más información sobre la lista de distribución Php-avanzado