Reputation: 181
I am getting an error message that says my image cannot be displayed because of errors. I looked at previous solutions to the problem but none has created any success. I made sure there are no blank lines, i have the html and the php seperate, and i have the right information before the header. Any help would be great as I think im missing something small. Code is below.
html:
<?php
$images = "SELECT product_images.img_name, product_images.img_tag, product_images.img_family, product_images.img_id FROM product_images
INNER JOIN product_list
ON product_images.img_tag = product_list.product_tag && product_images.img_family = product_list.name_family";
$img_list = mysql_query($images);
while($rows = mysql_fetch_array($img_list)) {
$img_name = $rows['img_name'];
$img_tag = $rows['img_tag'];
$img_family = $rows['img_family'];
$img_id = $rows['img_id'];
//echo $img_name;
?>
<div>
<img src="view.php?imgid=<?php echo $img_id; ?>" />
</div>
<?php
}
?>
php:
<?php
require_once('april25_connect.php');
$dir = "product_images/";
$img = $_GET['imgid'];
$query = "SELECT * FROM product_images WHERE img_id = '$img'";
//echo $query,'<br>';
$newid = mysql_query($query);
if (!$newid) {
echo "Query '$newid' failed <br />\n";
echo "Error: ".mysql_error()." <br />\n";
exit;
}else{
while($returned_id = mysql_fetch_array($newid)) {
$name = $returned_id['img_name'];
$tag = $returned_id['img_tag'];
$family = $returned_id['img_family'];
header ("Content-type: image/jpeg; image/gif; image/png");
$fullpath = $dir.$name;
echo $fullpath;
}
}
?>
Upvotes: 0
Views: 541
Reputation: 554
I think you're approach is wrong. Shouldn't your echo the $fullpath at the IMG html tag instead of the $img_id?
<img src="view.php?imgid=<?php echo $fullpath; ?>" />
Maybe I'm misunderstanding it, but it's hard to tell by partly seeing the content of the script.
P.S. I don't see your script returning the $img_id var for use.
I checked your product_images/ directory, it's a level up, that makes it $dir = "../product_images/";
Upvotes: 1