Primero debe guardar la imagen de la salida file_get_contents
a su base de datos. Y luego pones eso en imagecreatefromstring
y muestra tu imagen.
Aquí está el ejemplo simple. Tal vez esto te ayude :)
$data = file_get_contents("ACL.jpg");
$img = imagecreatefromstring($data);
header("Content-Type: image/jpeg");
imagejpeg($img);
EDITAR:
solo necesitas poner este código:
$statement->bind_result($imageid, $title, $image)
while ($statement->fetch()) {
if ($image == NULL) {
echo "Image data does not exist!";
} else {
$img = imagecreatefromstring($image);
header("Content-Type: image/jpeg");
imagejpeg($img);
}
}
CORRECCIÓN DE EDICIÓN:
uploads.php
En este archivo necesitas cambiar tu $statement->bind_param('sb', $title, $content);
convertirse en $statement->bind_param('ss', $title, $content);
if (isset($_POST['submit'])) {
$title = $_FILES['image']['name'];
$data = $_FILES['image']['tmp_name'];
$content = file_get_contents($data);
$query = "INSERT INTO images (title, image) VALUES (?, ?)";
$statement = $databaseConnection->prepare($query);
$statement->bind_param('ss', $title, $content);
$statement->execute();
$statement->store_result();
$creationWasSuccessful = $statement->affected_rows == 1 ? true : false;
if ($creationWasSuccessful)
{
echo "Works!";
} else {
echo 'failed';
}
}
showimage.php
y luego lo muestra usando esto:
$img = imagecreatefromstring($image);
header("Content-Type: image/jpeg");
imagejpeg($img);
en su última declaración
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query = "SELECT id,title,image FROM images WHERE id = ?";
$statement = $databaseConnection->prepare($query);
$statement->bind_param('i', $id);
$statement->execute();
$statement->store_result();
if ($statement->num_rows >= 1)
{
$statement->bind_result($imageid, $title, $image)
while ($statement->fetch()) {
if ($image == NULL) {
echo "Image data does not exist!";
} else {
$img = imagecreatefromstring($image);
header("Content-Type: image/jpeg");
imagejpeg($img);
}
}
}
}
Espero que esto también funcione bien, lo he probado y funciona bien... :)