Jump to content

[SOLVED] display image from DB link


coupe-r

Recommended Posts

I have links to my files in my DB.  ex. /apache/htdocs/img/test.jpg

 

When I echo the information, I just get an empty square where the image should be.

 

Now, I believe it will be the headers, but i have tried header('Content-type: image/jpeg') but it does not work.

 

Any other suggestions?

Link to comment
https://forums.phpfreaks.com/topic/155586-solved-display-image-from-db-link/
Share on other sites

$result = mysql_query("SELECT * FROM products");

$count = mysql_num_rows($result);

if($count < 17)
{
	$page = '<a href = "products.php">Page 1</a>';
}
	elseif($count < 37)
	{
		$page .= '<a href = "products.php?page=1">Page 1</a>' . "  ";
		$page .= '<a href = "products.php?page=2">Page 2</a>';
	}


$totalproducts = mysql_num_rows($result);

echo $page;
echo '<table width="750" border="0" align="center">';
echo '<tr>';


$i = 0;
while($row = mysql_fetch_array($result))
{
if( (($i % 4) == 0) && ($i != 0) )
{
	echo '</tr><tr>';
}

echo '<td width="25%" height="150" align="center">' . '<img src="' . $row['prod_img'] . '"/>' . '<br>' . $row['prod_name'] . '<br>' . '$' . $row['prod_price'] . '</td>';

$i++;

}

echo '</tr>';
echo '<table>';

?>

$result = mysql_query("SELECT * FROM products");

$count = mysql_num_rows($result);

if($count < 17)
{
	$page = '<a href = "products.php">Page 1</a>';
}
	elseif($count < 37)
	{
		$page .= '<a href = "products.php?page=1">Page 1</a>' . "  ";
		$page .= '<a href = "products.php?page=2">Page 2</a>';
	}


$totalproducts = mysql_num_rows($result);

echo $page;
echo '<table width="750" border="0" align="center">';
echo '<tr>';


$i = 0;
while($row = mysql_fetch_array($result))
{
if( (($i % 4) == 0) && ($i != 0) )
{
	echo '</tr><tr>';
}

echo '<td width="25%" height="150" align="center">' . '<img src="' . $row['prod_img'] . '"/>' . '<br>' . $row['prod_name'] . '<br>' . '$' . $row['prod_price'] . '</td>';

$i++;

}

echo '</tr>';
echo '<table>';

?>

 

Try this, it's untested.

 

<?php
$result = mysql_query("SELECT * FROM products");

$count = mysql_num_rows($result);

   if($count < 17)
   {
      $page = '<a href = "products.php">Page 1</a>';
   }
      elseif($count < 37)
      {
         $page .= '<a href = "products.php?page=1">Page 1</a>' . "  ";
         $page .= '<a href = "products.php?page=2">Page 2</a>';
      }


$totalproducts = mysql_num_rows($result);

echo $page;
echo '<table width="750" border="0" align="center">';
echo '<tr>';


$i = 0;
while($row = mysql_fetch_array($result))
{
   if( (($i % 4) == 0) && ($i != 0) )
   {
      echo '</tr><tr>';
   }

   /**
   * I'm assuming all your image's reside in the /img directory.
   */
   echo '<td width="25%" height="150" align="center">' . '<img src="img/' . substr($row['prod_img'], strrpos("/", $row['prod_img']) + 1, strlen($row['prod_img'])) . '"/>' . '<br>' . $row['prod_name'] . '<br>' . '$' . $row['prod_price'] . '</td>';
   
   $i++;
   
}

echo '</tr>';
echo '<table>';

?>

I tried it both ways.  The interesting part is:

 

When I right click on the empty box and click properties, it shows:

 

location http://..../apache/htdocs/img/test.jpg

type: text/html

image dim 24x24

size: unknown

alt: missing

 

The type is not an image.

Images are requested by browsers using a URL. URL's are relative to your document root folder. Based on what you have shown, you have a file system path stored as part of what you are calling a link.

 

Your document root folder appears to be apache/htdocs. Therefore, a valid URL (relative to your document root folder) would be http://yourdomain.com/img/test.jpg (using an actual domain) or http://localhost/img/test.jpg (on your local host development system.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.