Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: trying to integrate thumbnail viewer into my php forum

  1. #1
    Join Date
    Mar 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default trying to integrate thumbnail viewer into my php forum

    1) Script Title:
    image thumbnail viewer
    2) Script URL (on DD):
    http://dynamicdrive.com/dynamicindex4/thumbnail.htm
    3) Describe problem:

    I'm trying to integrate the thumbnail script into my forums for image uploads.

    I've integrated everything but the last bit where you set the images up as hrefs instead of img tags.

    The script requires you to format the images like this, as you can see from the instructions....

    Code:
    <p><a href="http://img201.imageshack.us/img201/6923/countryxb6.gif" rel="thumbnail"><img src="thumbnail.gif" style="width: 50px; height: 50px" /></a></p>
    Now in my forum's tag to html converter area there's a section that uses preg_replace to translate the bbcode into html for display in the forum.

    I'm not familiar with the pattern matching in php, and preg_replace requires you to use escape chars etc to format it in such a way that the string is replaced correctly.

    Currently, the line I'm trying to change looks like this.

    Code:
    Code: 
     $sb_message_txt = preg_replace("/\[img\](.*?)\[\/img\]/si","<img src=\"$1\" border=\"0\" />",$sb_message_txt);
    Every time I try to format the href with this pattern recognition syntax, I break my forum. I've read a rather large reference on preg_replace, and pattern matching in php, but have thus far been unsuccessful.

    Can someone show me how it should look? I have several lines I need to format this way, if someone could help me by doing the first one as an example of how to do it with an href, that would be great.

    This is what I've done so far, that has not worked.

    Code:
    $sb_message_txt = preg_replace("/\[img\](.*?)\[\/img\]/si",<p><a href=\"$1\" rel=\"thumbnail\"><img src=\"thumbnail.gif\" style=\"width: 50px; height: 50px\" /></a></p>,$sb_message_txt);
    I got a parse error with that one.

    I also posted this in the php forum but got no replies after 3 days so I'm posting it here. Admins can delete the other one.

    Any help would be appreciated,

    Rich

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You may want to try putting quotes around the string like so:

    Code:
    $sb_message_txt = preg_replace("/\[img\](.*?)\[\/img\]/si","<p><a href=\"$1\" rel=\"thumbnail\"><img src=\"thumbnail.gif\" style=\"width: 50px; height: 50px\" /></a></p>",$sb_message_txt);
    If that still doesn't work, post the parse error so that we have an idea of what's going on.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Mar 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    cool, will do, thanks. I should have thought of posting the parse error. Duh. I'll post the results.

    Rich

  4. #4
    Join Date
    Mar 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK, now it doesn't throw the parse error, but the small image is a redx and the new image doesn't show up in the pretty div that the script draws, just in a new window.

    Odd. I'm looking into it deeper.

    Edit: partially fixed, see next post.... disregard this one...

    Rich
    Last edited by gn0stik; 03-26-2007 at 11:03 PM.

  5. #5
    Join Date
    Mar 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This is the current code, that doesn't throw a parse error..

    Code:
    $sb_message_txt = preg_replace("/\[img\](.*?)\[\/img\]/si","<p><a href=\"$1\" rel=\"thumbnail\"><img src=\"$1\" style=\"width: 150px;\" /></a></p>",$sb_message_txt);
    I got rid of the height part of the style, as It retains proportion this way, and increased it to 150px as you can see.

    I also changed the img tag to use the same variable so that it loads the same image as the thumbnail. Not making it any smaller or faster to load, but I don't have a script that will automatically generate the thumbs anyway.

    This is the html that it produces.

    Code:
    <p><a href="http://www.dynamicdrive.com/dynamicindex4/portrait.jpg" rel="thumbnail"><img src="http://www.dynamicdrive.com/dynamicindex4/portrait.jpg" style="width: 150px;" /></a></p>
    Looks correct to me, not sure why it's not firing the script.

    Internet explorer throws an "error: expected identifier, string, or number" between these lines in the script.

    Code:
    targetlinks:[], //Array to hold links with rel="thumbnail"
    
    if (document.getElementById){
    So say the line starting with targetlinks: is 10 and the beginning of that if statement is 12

    the line number it throws and error for is 11. Which would lead me to believe the erorr is actually on 10. But I see nothing wrong with that. The script is supposed to load up that array, is it not? I mean, I'm not supposed to initialize it am I?

    The script it self, in our imaginary line numbering scheme I stated says on line number 8, "no need to edit beyond here".

    And that's exactly how it's running in the example.

    I don't get it.

    Rich
    Last edited by gn0stik; 03-26-2007 at 11:01 PM.

  6. #6
    Join Date
    Mar 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    UPDATE::

    OK, working in IE7 now, but not FF. I get a little tiny sliver of a thumbnail in spite of the fact that it shows ok in IE, and when I click it the "loading...." flashes, but no image window pops up.

    Rich

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Can you either post (or PM) a link to the problem page so that we can take a look at it to find out what's going on with it?
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #8
    Join Date
    Mar 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK, it's working in IE7 and FF now, with no problems that I can see however I still get the script error in ie7 mentioned above.

    It's odd, it works but still throws that error in iE7.

    my site don't think i'm cook please.

    unfortunately, you will need to log in in order to view the forums.

  9. #9
    Join Date
    Mar 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I can remove the login requirement for you to see the forums without logging in. If that helps.

  10. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I'm logged in right now, and currently looking at the Image Thumbnails topic. Not sure why (probably something with server cache or whatnot), but the first two images don't show up until I view it using the link (copying it and pasting it in the address bar).
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

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