Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts

    Question Displaying images from db?

    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 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.

  • #2
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    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?

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    $var = str_replace('/old/dirpath/', '/new/dirpath/', $var);

  • Users who have thanked MattF for this post:

    cosmicsea (11-19-2010)

  • #4
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    Code:
    $var = str_replace('/old/dirpath/', '/new/dirpath/', $var);
    I cannot seem to get that to work. I will keep trying.

  • #5
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Never mind I got it working. I was overlooking things. Thanks Matt!

  • #6
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    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 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[0] = str_replace('./thumbs/''/admin/thumbs/'$row[0])."'></a></div>
                "
    ;


    ?>
    Last edited by cosmicsea; 11-19-2010 at 02:49 AM.

  • #7
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Yeah I cannot seem to get this to work right. Anymore help from anyone is much appreciated.

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    The echo lines want to be:

    Code:
    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.

  • Users who have thanked MattF for this post:

    cosmicsea (11-19-2010)

  • #9
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattF View Post
    The echo lines want to be:

    Code:
    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.

  • #10
    Regular Coder
    Join Date
    Jan 2010
    Location
    Washington
    Posts
    223
    Thanks
    34
    Thanked 0 Times in 0 Posts
    nope I found the problem. It's in my db, some things are not being saved correctly. Thanks Matt.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •