Advertisement
Komtec1

De BLOB -MySQL- a imagen con PHP

Mar 8th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. <?
  2. //script para guardar imagenes desde una base de datos con contenido BLOB
  3. $dbhost = 'localhost';
  4. $dbname = 'nombredelabase';
  5. $dbusername = "usuario";
  6. $dbuserpass = 'contraseña';
  7. $demo1 = mysqli_connect($dbhost, $dbusername, $dbuserpass, 'credencial') or trigger_error(mysql_error(),E_USER_ERROR);
  8. $consulta = mysqli_query($demo1, "SELECT * FROM imagenes");
  9. while ($dato = mysqli_fetch_array($consulta, MYSQLI_ASSOC))
  10. {
  11.     $foto = $dato['Foto'];
  12.     $id = $dato['idPersona'];
  13.         //extrae la foto del blob
  14.         $source_img = imagecreatefromstring($foto);
  15.         $file = 'imagenes/'. $id . '_foto.jpg';
  16.         $imageSave = imagejpeg($source_img, $file, 90);
  17.         imagedestroy($source_img);
  18. }
  19.  
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement