got this script for displaying photos the problem is it falls apart when it returns the image
Code pic.php
<?php
$conn = mysqli_connect("localhost", "root", "admin", "test");
$conn->query("CREATE TABLE files (id INTEGER PRIMARY KEY AUTO_INCREMENT,data BLOB)");
$stmt = $conn->prepare("INSERT INTO files VALUES(NULL, ?)");
$stmt->bind_param("s", $data);
$file = "eyes.jpg";
$fp = fopen($file, "r");
$size = 0;
while ($data = fread($fp, 1024)) {
$size += strlen($data);
$stmt->send_long_data(0, $data);
}
$data = file_get_contents("eyes.jpg");
if ($stmt->execute()) {
print "$file ($size bytes) was added to the files table\n";
} else {
die($conn->error);
}
?>
code for pic1.php the bit that falls apart is bold
<?php
if (empty($_GET['id'])) {
$conn = mysqli_connect("localhost", "root", "admin", "test");
$result = $conn->query("SELECT id, length(data) FROM files LIMIT 20");
if ($result->num_rows == 0) {
print "No images!\n";
print "<a href=\"mysqli_blob1.php\">Click here to add one<a>\n";
exit();
}
while ($row = $result->fetch_row()) {
print "<a href=\"$_SERVER[PHP_SELF]?id=$row[0]\">";
print "image $row[0] ($row[1] bytes)</a><br />\n";
}
exit();
}
[B]$stmt = $conn->prepare("SELECT data FROM files WHERE id = ?");[/B]
$stmt->bind_param("i", $_GET['id']);
$stmt->execute();
$data = null;
$stmt->bind_result($data);
if (!$stmt->fetch()) {
die("No such image!");
}
header("Content-type: image/jpeg");
print $data;
?>
any body that can explain why would be great
thanks in advance
john