SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 Code:
    <?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.

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,217
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pavelazad View Post
    Hi,

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

    PHP Code:
    <?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:
    Code:
    <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>

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hii,

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

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,217
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    Can you copy and paste the HTML output (by doing a view source and copying the link/image html markup here)?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is the thing i m getting from view soruce. thanks.
    HTML Code:
    <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>

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,217
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    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
    PHP Code:
    $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
    PHP Code:
    $link1=("./admin/images/".rawurlencode(trim($pid))."/h66.jpg"); 
    $link2=("./admin/images/".rawurlencode(trim($pid))."/h6.jpg"); 

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its working now. thanks a lot for your help.

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,217
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    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.


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
  •