coupe-r Posted April 25, 2009 Share Posted April 25, 2009 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? Quote Link to comment Share on other sites More sharing options...
Prismatic Posted April 25, 2009 Share Posted April 25, 2009 <?php $file = "path_to_file.jpg"; header('Content-type: image/jpeg'); readfile($file); exit; ?> Quote Link to comment Share on other sites More sharing options...
coupe-r Posted April 25, 2009 Author Share Posted April 25, 2009 Thanks for the fast reply. When I add that, all that displays on the screen is the link to my site. 192,168.1.107/test1.php Quote Link to comment Share on other sites More sharing options...
trq Posted April 25, 2009 Share Posted April 25, 2009 Can you at least post the relevent code? Were not mind readers. Quote Link to comment Share on other sites More sharing options...
coupe-r Posted April 25, 2009 Author Share Posted April 25, 2009 $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>'; ?> Quote Link to comment Share on other sites More sharing options...
Prismatic Posted April 25, 2009 Share Posted April 25, 2009 $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>'; ?> Quote Link to comment Share on other sites More sharing options...
coupe-r Posted April 25, 2009 Author Share Posted April 25, 2009 Unfortunately, I get the same results. Empty square with an icon inside. Quote Link to comment Share on other sites More sharing options...
Prismatic Posted April 25, 2009 Share Posted April 25, 2009 Unfortunately, I get the same results. Empty square with an icon inside. View the source of the generated page. What is the src="" value for the image? Quote Link to comment Share on other sites More sharing options...
coupe-r Posted April 25, 2009 Author Share Posted April 25, 2009 <img src="apache/htdocs/img/test.jpg"/> Quote Link to comment Share on other sites More sharing options...
trq Posted April 25, 2009 Share Posted April 25, 2009 Obviously thats not a valid path. Is it missing an initial / ? Quote Link to comment Share on other sites More sharing options...
coupe-r Posted April 25, 2009 Author Share Posted April 25, 2009 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 25, 2009 Share Posted April 25, 2009 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.) Quote Link to comment Share on other sites More sharing options...
coupe-r Posted April 25, 2009 Author Share Posted April 25, 2009 Unreal...... THANK YOU!!!!!!!!! Moron alert ------> ME Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.