Jump to content

[SOLVED] Can't display and link image correctly


iamsofuckingcool

Recommended Posts

Hello,

 

I am trying to display an image thumbnail that links to the image file.

            $maincontent .= "<br />\n<div id=\"result". $row['id'] ."\" class=\"result\">\n";
            $img = compimg($row['id']);
            $thumb = compthumb($row['id']);

            $maincontent .= "<a href=\"$img\" rel=\"lightbox\"><img src=\"$thumb\" class=\"preview\" /></a>";

 

functions are

 

    //Returns the filename of the image for a specified post
    function compimg($id) {
        $files = glob("images/Posts/$id.*");
        if ($files == false)
            return '';
        if (!isset($files[0]))
            return '';
        else
            return $files[0];
    }
    
    //Returns the filename of the thumbnail for a specified post
    function compthumb($id) {
        $files = glob("images/Post_Thumbs/$id.*");
        if ($files == false)
            return '';
        if (!isset($files[0]))
            return '';
        else
            return $files[0];
    }

 

the result is supposed to be

 

href = "http://www.iasfc.com/images/48.gif

src = "http://www.iasfc.com/iasfc.com/images/Post_Thumbs/48.gif"

 

i keep getting:

 

href = "http://www.iasfc.com/comment/iasfc.com/images/48.gif

src = "http://www.iasfc.com/comment/iasfc.com/images/Post_Thumbs/48.gif"

 

How do i eliminate the comment dirctory in the URL?

 

 

Link to comment
Share on other sites

Thanks for the quick response. Here is the whole shebang. does this help?


<?php
require_once('recaptchalib.php');
//include('compimg.php');
$comment = $_POST['comment'];

if(!$comment){

    $q = "SELECT * FROM `comps` WHERE `id` = '". $comp ."'";

    $r = mysql_query($q);

    $voting_array = mysql_fetch_array(mysql_query("SELECT * FROM `votes` WHERE `ip`='$ip'"));

    $vote_explode = explode(',', $voting_array['comp_id']);

    foreach($vote_explode as $vote_ex){

        $vote_ex = explode(":", $vote_ex);

        $compnum = $vote_ex[0];
        $compvote = $vote_ex[1];
        $compvotearray[$compnum] = $compvote;
    }

    if(mysql_num_rows($r) > 0){
        while($row = mysql_fetch_array($r, MYSQL_ASSOC)){
            // count the comments
            $commentsCountQuery = "select * from comments where comp_id=" . $comp;
            $commentsCountResult = mysql_query($commentsCountQuery);
            $commentsCount = mysql_num_rows($commentsCountResult);

            $maincontent .= "<br />\n<div id=\"result". $row['id'] ."\" class=\"result\">\n";
		$img = compimg($row['id']);
            $thumb = compthumb($row['id']);

            $maincontent .= "<a href=\"$img\" rel=\"lightbox\"><img src=\"$thumb\" class=\"preview\" /></a>";

            $maincontent .= stripslashes($row['message']) ."\n<br /><br />\n<div class=\"clear\"></div>\n";
            $maincontent .= '<span class="sentBy"><span class="lside">('. $commentsCount .') comments </a></span>';
            $maincontent .= '<a href="" class="commlink">IASFC #'. $row['id'] .'</a>';

            if(!$compvotearray[$row['id']]){

                $maincontent .= '<span id="vote_buttons'. $row['id'] .'" class="vote_buttons">
                <span id="a1votes_count'. $row['id'] .'">
                <a id=":'. $row['id'] .':1:'. $row['votes1'] .':'. $row['votes2'] .':" class="vote_up" title="'. $phrase1 .':'. $phrase2 .'" href="javascript:;">
                '. $phrase1 .' ('. $row['votes1'] .')</a></span>';
                $maincontent .= '   -   <span id="a2votes_count'. $row['id'] .'">
                <a id=":'. $row['id'] .':2:'. $row['votes1'] .':'. $row['votes2'] .':" class="vote_down" title="'. $phrase1 .':'. $phrase2 .'" href="javascript:;">
                '. $phrase2 .' ('. $row['votes2'] .')</a>
                </span></span><br />';
            } else {

                $maincontent .= '<span id="vote_buttons'. $row['id'] .'" class="vote_buttons voted">
                <span id="a1votes_count'. $row['id'] .'">
                '. $phrase1 .' ('. $row['votes1'] .')</span>';
                $maincontent .= '   -   <span id="a2votes_count'. $row['id'] .'" class="vote_buttons voted">
                '. $phrase2 .' ('. $row['votes2'] .')
                </span></span><br />';

            }

 

Link to comment
Share on other sites

change

return $files[0];

 

to

return str_replace('comments/','',$files[0]);

 

thats the only thing I can see to fix that maybe glob somehow gets the 'comments/' or whatever but if its not THERE it hasta be somewhere else in your script

 

lol I put "comments" instead of "comment" change:

return str_replace('comments/','',$files[0]);

 

to

return str_replace('comment/','',$files[0]);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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