Forum Moderators: coopster

Message Too Old, No Replies

Hiding image link through redirector?

         

ajs83

3:37 am on Jun 2, 2006 (gmt 0)

10+ Year Member



I want to hide the location of an embedded image by using a redirector link. I have the code below that works if viewing the url, but it is not showing the image when used inside of an image tag.

How do I get the the redirection link to work inside of an image tag?


$id = $_GET['pid'];

$result = mysql_query("select * from pictures");
$rab=mysql_fetch_array($result);
$image=$rab["image"];

echo "$image";

dreamcatcher

7:15 am on Jun 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo '<img src="'.$image.'" alt="" title="" border="0">';

dc

ajs83

8:03 pm on Jun 2, 2006 (gmt 0)

10+ Year Member



Oh, I know that, I meant to tell the browser that the script above is going to send it back an image.

The one above works fine when you visit the direct url, but when I try to include the link (ie: www.example.com/image.php?pid=1) inside of an image tag, it gives me a broken image.

coopster

8:29 pm on Jun 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Our PHP Forum Library [webmasterworld.com] has a thread that you should read titled How to convert image blob files back to image [webmasterworld.com].

ajs83

8:54 pm on Jun 2, 2006 (gmt 0)

10+ Year Member



The database only contains a link to the image, it's not a blob.

coopster

9:08 pm on Jun 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Then based on your statement ...


The one above works fine when you visit the direct url, but when I try to include the link (ie: www.example.com/image.php?pid=1) inside of an image tag, it gives me a broken image.

... there shouldn't be any difference. Using the <img> element as shown by dc there with the same url as what you key into the browser address bar should produce the same thing.

ajs83

9:33 pm on Jun 2, 2006 (gmt 0)

10+ Year Member



That's the exact code that I have, but I don't know why it's not working. I've checked the error logs and nothing is showing up either.

dreamcatcher

5:48 am on Jun 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You say your image variable is correct when you view the raw code, but is the actual path to this file correct? Do you see a red cross in IE?

dc

ajs83

10:34 pm on Jun 3, 2006 (gmt 0)

10+ Year Member



The link source in the database is correct as it shows the image correctly when visiting the url, but it will not work when the link is inside of an image tag (yes, the tag is correct).

dreamcatcher

10:36 am on Jun 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, I`m with you now.

Try something like this:


$id = $_GET['pid'];
$result = mysql_query("select * from pictures");
$rab=mysql_fetch_array($result);

$image=$rab["image"];

header('Content-Type: image/jpeg');
readfile($image);

dc

ajs83

8:43 pm on Jun 4, 2006 (gmt 0)

10+ Year Member



That works. Thanks!