...

View Full Version : Displaying images from db?



cosmicsea
11-19-2010, 01:11 AM
I am trying to use image thumb links from my db. I have a folder in my admin that stores thumbs of pictures that my crawler comes across and in the the db the thumb text is stored like this for example ./thumbs/db1/1...search1_...1651_-_1201-_-ball.gif

This is my code

<?php
$link_click = "$include_dir/media_counter.php?url=$url_crypt";
$link_end = "&query=index&amp;db=$db&amp;prefix=$prefix";
echo "";
$result=mysql_query("select thumb_link, media_link from ".$mysql_table_prefix."media ORDER BY last_click DESC LIMIT 5");
while ($row=mysql_fetch_row($result))
echo "<div style='margin:4px;float:left;'>
<a href='".$link_click."".($row[1])."".$link_end."' target='_blank'><img src='".($row[1])."' height='100' width='100'></a></div>
";
?>

Right now I am aware I am basically hot linking and displaying these pictures as 100 by 100. I am trying to show the last 5 images clicked but i cannot figure out what to do to get my thumbs to show so I don't have to hot link to huge files. The thumbs directory is /admin/thumbs/db1. Everything I have tried seems to only show the text "./thumbs/db1/1...search1_...1651_-_1201-_-ball.gif" instead of an image. Can anyone help me figure this out? Thanks.

cosmicsea
11-19-2010, 01:50 AM
All I can think of is to do a preg_replace or something to remove the .
before ./thumbs/db1/1...search1_...1651_-_1201-_-ball.gif and replace with admin/
If I goto domain.com/admin/thumbs/db1/1...search1_...1651_-_1201-_-ball.gif it shows the thumb just fine.
$row[0] shows ./thumbs/db1/1...search1_...1651_-_1201-_-ball.gif
Anybody know something that could help?

MattF
11-19-2010, 02:11 AM
$var = str_replace('/old/dirpath/', '/new/dirpath/', $var);

cosmicsea
11-19-2010, 02:58 AM
$var = str_replace('/old/dirpath/', '/new/dirpath/', $var);

I cannot seem to get that to work. I will keep trying.

cosmicsea
11-19-2010, 03:38 AM
Never mind I got it working. I was overlooking things. Thanks Matt!

cosmicsea
11-19-2010, 03:46 AM
I dont know if this is what you meant to do but it works but the 4th result always never shows and makes the directory the whole server directory so it is invalid. I don't see why it would do this. Anyone have any ideas as to why it would be doing this?
This is the directory the 4th result always shows for some reason.
/home/public_html/domain.com/public/admin/thumbs/db1/1...search1_...94633_-_57860-_-IMG_0441.gif


<?php
$link_click = "$include_dir/media_counter.php?url=$url_crypt";
$link_end = "&query=index&amp;db=$db&amp;prefix=$prefix";


echo "";
$result=mysql_query("select thumb_link, media_link from ".$mysql_table_prefix."media ORDER BY last_click DESC LIMIT 5");
while ($row=mysql_fetch_row($result))
echo "<div style='margin:4px;float:left;'>
<a href='".$link_click."".($row[1])."".$link_end."' target='_blank'><img src='".$row[0] = str_replace('./thumbs/', '/admin/thumbs/', $row[0])."'></a></div>
";


?>

cosmicsea
11-19-2010, 05:01 AM
Yeah I cannot seem to get this to work right. Anymore help from anyone is much appreciated.

MattF
11-19-2010, 02:24 PM
The echo lines want to be:



print('<p>'.$row[0].'</p>');

echo '<div style="margin:4px;float:left;">
<a href="'.$link_click.($row[1]).$link_end.'" target="_blank"><img src="'.str_replace('./thumbs/', '/admin/thumbs/', $row[0]).'"></a></div>';


As to why the path is incorrect, print the original before you alter it to see what is being supplied, as shown above.

cosmicsea
11-19-2010, 10:27 PM
The echo lines want to be:



print('<p>'.$row[0].'</p>');

echo '<div style="margin:4px;float:left;">
<a href="'.$link_click.($row[1]).$link_end.'" target="_blank"><img src="'.str_replace('./thumbs/', '/admin/thumbs/', $row[0]).'"></a></div>';


As to why the path is incorrect, print the original before you alter it to see what is being supplied, as shown above.

It is weird. It seems to work for the most part but that 4th result is always the same

./thumbs/db1/1...search1_...82009_-_52273-_-IMG_2202.gif

./thumbs/db1/1...search1_...32398_-_20418-_-v3j5oy.gif

./thumbs/db1/1...search1_...1651_-_1201-_-ball.gif

/home/public_html/domain.com/public/admin/thumbs/db1/1...search1_...94633_-_57860-_-IMG_0441.gif

./thumbs/db1/1...search1_...32398_-_20421-_-fuxrb6.gif

I don't even see how it is doing that.. I will keep messing with it and try to get it to stop, if not maybe I need to figure something else out.

cosmicsea
11-19-2010, 10:34 PM
nope I found the problem. It's in my db, some things are not being saved correctly. Thanks Matt.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum