ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-spanish
php-spanish
Re: [PHP-ES] MySQL + Imagick
by Martin Scotta other posts by this author
Oct 23 2009 1:47PM messages near this date
[PHP-ES] MySQL + Imagick | [PHP-ES] XAMPP y ORACLE
Pues creo que el problema esta aqui

$query = 'INSERT INTO foto (foto) VALUES ("$blob");';

Estas seguro que la informacion llega correctamente a la base de datos?
Haz la prueba de bajar el contenido de un registro a un archivo y mira si tu
sistema puede dibujar la imagen. Seguramente necesitaras escapar ese blob
antes de enviarlo a la base.
*

*2009/10/23 nestea <nestea1974@[...].es> 

>  O como guardar y extraer im�genes de una base de datos.
>  Todo lo refente al trabajo con la imagen funciona en el c�digo si comento
>  lo referente a SQL... pero no se que hago mal a la hora de guardar y
>  recuperar la imagen :(
>  El c�digo es:
> 
>  <?php
> 
>           if (is_uploaded_file($_FILES['foto']['tmp_name'])) {
> 
>                   move_uploaded_file($_FILES['foto']['tmp_name'],
>  "../ruta/".$_FILES['foto']['name']);
> 
> 
>                  $image = new Imagick("../ruta/".$_FILES['foto']['name']);
> 
>                  $image->adaptiveResizeImage(180,120);
> 
>                  $blob = $image->getImageBlob(); //ahora $blob es un
>  strig....la foto es texto
> 
> 
>                  //guardo la cadena $blob en la base de datos
> 
>                  $mysqli = new mysqli ('localhost', 'root', 'xxx',
>  'nombredb') or die (mysqli_connect_error());
> 
>                  $query = 'INSERT INTO foto (foto) VALUES ("$blob");';
> 
>                  $mysqli->query($query) or die (mysqli_error());
> 
> 
>                  //ahora quiero recuperar la imagen
> 
>                  $result = $mysqli->query("SELECT `foto`.`foto`, `foto`.`id`
>  FROM fotop WHERE id = '0';") or die (mysqli_error());
> 
>                  while ($fila = $result->fetch_object()) {
> 
>                      $resultado = $fila->fotop; //solo hay un registro...
>  aqu� est� la cadena
> 
>                  }
> 
>                  $result->close();
> 
>                  $mysqli->close();
> 
> 
>                  //ahora quiero sacar la foto por pantalla
> 
>                  $porPantalla = new Imagick();
> 
>                  $porPantalla->readImageBlob($resultado); //leo la imagen de
>  la cadena
> 
>                  header('Content-type: image/jpeg'); echo $porPantalla;
> 
>           }
> 
>           //...
> 
>  ?>
> 
>  P.D: creo que esta vez he enviado el c�digo legible, disculparme por le
>  correo anterior. Gracias :)
> 
> 
> 
> 




-- 
Martin Scotta
Thread:
Nestea
Martin Scotta

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved