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
[PHP-ES] MySQL + Imagick
by Nestea other posts by this author
Oct 23 2009 1:37PM messages near this date
[PHP-ES] Oferta Laboral - Argentina Capital Federal | Re: [PHP-ES] MySQL + Imagick
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 S
QL... 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']['nam
e']);

��� ��� ��� ��� $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', 'n
ombredb') 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`, `fot
o`.`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 im
agen de la cadena

��� ��� ��� ��� header('Content-type: image/jpeg'); echo $porPantall
a;

��� ��� �}

��� ��� �//...

?> 

P.D: creo que esta vez he enviado el c�digo legible, disculparme por le correo anterior. G
racias :)



      
Thread:
Nestea
Martin Scotta

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