Php variable in image link...need help

Hi,

I am having a problem with loading image from a link where one of the folder name i getting from user input.


<?php
include "dbconnect.php";
$link=dbconnect();
$pid=$_GET['pid'];
$link1=("./admin/images/".$pid."/h66.jpg");
$link2=("./admin/images/".$pid."/h6.jpg");

<a href= <?php echo $link1 ?> class = 'cloud-zoom' id='zoom1'
            rel="adjustX: 20, adjustY:-5, tint:'#FFFFFF', tintOpacity: 0.4">
            <img src=<?php echo $link2 ?> alt='' title="Optional title display" />
        </a>

with this code image doesn’t load. if I put your mouse on the broken link i see admin/images/1861 but dont see the image name. here 1861 is the $pid im getting from user. any one can tell me where is the problem please.

Try placing the image path in quotes like so:


<a href='<?php echo $link1 ?>' class = 'cloud-zoom' id='zoom1' 
            rel="adjustX: 20, adjustY:-5, tint:'#FFFFFF', tintOpacity: 0.4"> 
            <img src='<?php echo $link2 ?>' alt='' title="Optional title display" /> 
        </a>

hii,

I am getting the same thing. is there any other way i can fix it?

Can you copy and paste the HTML output (by doing a view source and copying the link/image html markup here)?

this is the thing i m getting from view soruce. thanks.


<a href= ./admin/images/1861 /h66.jpg class = 'cloud-zoom' id='zoom1'
            rel="adjustX: 20, adjustY:-5, tint:'#FFFFFF', tintOpacity: 0.4">
            <img src='./admin/images/1861 /h6.jpg' alt='' title="Optional title display" />
        </a>

Ah okay. Is there actually a space in the folder name?

First things first (in case there is a space in the folder name
Change your code to this

$link1=("./admin/images/".rawurlencode($pid)."/h66.jpg"); 
$link2=("./admin/images/".rawurlencode($pid)."/h6.jpg"); 

If you are not expecting a space in the folder name, then this should work

$link1=("./admin/images/".rawurlencode(trim($pid))."/h66.jpg"); 
$link2=("./admin/images/".rawurlencode(trim($pid))."/h6.jpg"); 

its working now. thanks a lot for your help.

Just wanted to provide an explanation on rawurlencode().

In short, you would use this method when your folder/page contains characters that are not web safe. For example, spaces, plus signs, slashes, ampersands, etc. It takes those unsafe characters and turns them into their hexadecimal counterparts allowing them to be interpreted by the browser.