Page 1 of 1

image display problem!!

Posted: Sun Sep 07, 2008 10:12 am
by kanchan
i have a link : http://www.test.com/thumb.php?img=wallp ... =800&h=600

when a user click on that link, that link should open to a new window and display the image but instead of displaying the image, it automatically downloads the image..

So how to display the image in new window??
could you please help me out??

below is the code for thumb.php

Code: Select all

 
<?
function thumb_on_fly($img,$h=null,$w=null,$max=80)
{
    if(file_exists($img))
    {
        if( isset($h) && isset($w) )
        {
            $s = getimagesize($img);
            $sx = $s[0];
            $sy = $s[1];
            $source = imagecreatefromjpeg($img);
            $target = imagecreatetruecolor($w, $h);
            $copy = imagecopyresampled($target, $source, 0, 0, 0, 0, $w, $h, $sx, $sy);
            $image = imagejpeg($target);
            imagedestroy($target);
            return $image;
        }
        else // scale automatically until < $max while keeping aspect ratios
        {
            $s = getimagesize($img);
            $sx = $s[0];
            $sy = $s[1];
 
            if($sx > $sy/2)
            {
                $nw=$max;
                $nh=($sy/$sx)*$nw;
            }
            else
            {
                $nh=$max*2;
                $nw=($sx/$sy)*$nh;
            }
 
            $source = imagecreatefromjpeg($img);
            $target = imagecreatetruecolor($nw, $nh);
            $copy = imagecopyresampled($target, $source, 0, 0, 0, 0, $nw, $nh, $sx, $sy);
            $image = imagejpeg($target);
            imagedestroy($target);
            return $image;
        }
    }
}
 
if ( isset($_GET['img']) && !isset($_GET['h']) && !isset($_GET['w']) && !isset($_GET['max']) )
{
    header("content-type: image/jpg");
    thumb_on_fly($_GET['img']);
}
elseif ( isset($_GET['img']) && isset($_GET['h']) && isset($_GET['w']) && !isset($_GET['max']) )
{
    header("content-type: image/jpg");
    thumb_on_fly($_GET['img'],$_GET['h'],$_GET['w']);
}
elseif ( isset($_GET['img']) && !isset($_GET['h']) && !isset($_GET['w']) && isset($_GET['max']) )
{
    header("content-type: image/jpg");
    thumb_on_fly($_GET['img'],null,null,$_GET['max']);
}
?>
 

Re: image display problem!!

Posted: Sun Sep 07, 2008 11:20 am
by starram
Hey, IN your code I don't see any link, where you create hyperlink for the image.

what you can do is, Create a hyperlink for the image & set the target="_blank"

thanks

Re: image display problem!!

Posted: Sun Sep 07, 2008 11:24 am
by kanchan
http://www.test.com/thumb.php?img=wallp ... =800&h=600

this is the hyperlink, opens new window but the problem is, it doesnt diplay the image, it directly download the image as soon as the new window opens....

Re: image display problem!!

Posted: Sun Sep 07, 2008 11:26 am
by andyhoneycutt
does this problem occur across all browsers?

Re: image display problem!!

Posted: Sun Sep 07, 2008 11:36 am
by kanchan
yeah i guess....

i want the opening window should display the resized image instead of direct downloading.....


:roll: :roll: :roll:

Re: image display problem!!

Posted: Sun Sep 07, 2008 11:37 am
by starram
Please create a proper hyperlink for the image. I wnt on the same link and couldn't find the image you want to show.

You can type something like this.

styles/subsilver2/imageset/site_logo.gif

Re: image display problem!!

Posted: Sun Sep 07, 2008 11:49 am
by kanchan
http://www.merobike.com/test/thumb.php? ... =800&h=600

try this out.. this link directly downloads the image instead of showing in the browser

do you know why??

Re: image display problem!!

Posted: Sun Sep 07, 2008 12:20 pm
by starram
It is behaving like that due to following code.

if ( isset($_GET['img']) && !isset($_GET['h']) && !isset($_GET['w']) && !isset($_GET['max']) )
{
header("content-type: image/jpg");
thumb_on_fly($_GET['img']);
}
elseif ( isset($_GET['img']) && isset($_GET['h']) && isset($_GET['w']) && !isset($_GET['max']) )
{
header("content-type: image/jpg");
thumb_on_fly($_GET['img'],$_GET['h'],$_GET['w']);
}
elseif ( isset($_GET['img']) && !isset($_GET['h']) && !isset($_GET['w']) && isset($_GET['max']) )
{
header("content-type: image/jpg");
thumb_on_fly($_GET['img'],null,null,$_GET['max']);
}


Try this

if ( isset($_GET['img']) && !isset($_GET['h']) && !isset($_GET['w']) && !isset($_GET['max']) )
{
echo "<a href=url/$_GET[img]>title</a>";
}
elseif ( isset($_GET['img']) && isset($_GET['h']) && isset($_GET['w']) && !isset($_GET['max']) )
{
echo "<a href=url/$_GET[img]>title</a>";
}
elseif ( isset($_GET['img']) && !isset($_GET['h']) && !isset($_GET['w']) && isset($_GET['max']) )
{
echo "<a href=url/$_GET[img]>title</a>";
}

Re: image display problem!!

Posted: Sun Sep 07, 2008 12:26 pm
by kanchan
if ( isset($_GET['img']) && !isset($_GET['h']) && !isset($_GET['w']) && !isset($_GET['max']) )
{
echo "<a href=url/$_GET[img]>title</a>";
}
elseif ( isset($_GET['img']) && isset($_GET['h']) && isset($_GET['w']) && !isset($_GET['max']) )
{
echo "<a href=url/$_GET[img]>title</a>";
}
elseif ( isset($_GET['img']) && !isset($_GET['h']) && !isset($_GET['w']) && isset($_GET['max']) )
{
echo "<a href=url/$_GET[img]>title</a>";
}
will that code generate the image to defined height and width i.e : 800x600 ??

Re: image display problem!!

Posted: Sun Sep 07, 2008 12:34 pm
by andyhoneycutt
I'm running firefox 3.0.1 and the page displays an image for me, does not direct download. There are issues with IE 7 and direct downloads when they should be displayed in the browser. Have you tested this across multiple browsers?

Re: image display problem!!

Posted: Sun Sep 07, 2008 11:01 pm
by starram
No it will display the original image. U can try lot of other things for that. Like passing the image id or name and setting width and height their with img tag.

Another thing u can re-size the image.