Results 1 to 8 of 8

Thread: Secret Location For Pictures?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Secret Location For Pictures?

    I want to display pictures from some folder without allowing the user to see the their folder name when he click (rightclick on the photo=>properties).
    So I make a seperate file called printit, it contains:
    <?php
    echo "<img src="IMGFOL/".$_GET['imgname'].">";
    ?>

    and then when I want to display a picture for the user I write:
    echo "<img src='printit.php?imgname=12'>";

    but the picture wasn't displayed! while the generated url is correct, when I copy it and put in address bar, the picture is displayed.
    what is the problem?

    thank's in advance

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: Secret Location For Pictures?

    it give me "X" instead of the picture, while the picture is exist!

  3. #3
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Secret Location For Pictures?

    Your quotes are the issue.

    PHP Code:
    <?php
    echo "<img src="IMGFOL/".$_GET['imgname'].">";
    ?>
    //should be
    <?php
    echo "
    <img src='IMGFOL/".$_GET['imgname']."'/>";
    ?>

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: Secret Location For Pictures?

    also didn't work!
    any other solution?
    thank's

  5. #5
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Secret Location For Pictures?

    You have an img tag inside of an img tag, thats why.

    HTML Code:
    <img src='printit.php?photo=dclamp.jpg>
    Printit.php:

    PHP Code:
    <?php
    $imgname 
    $_GET['photo'];
    $folderlocation "images/";

    echo 
    $folderlocation $imgname;
    ?>
    --------------------------------------

    Here was your code:

    PHP Code:
    <?php
    echo "<img src="IMGFOL/".$_GET['imgname'].">";
    ?>
    HTML Code:
    <img src='printit.php?imgname=12'>
    Would Output:

    HTML Code:
    <img src='<img src='IMGFOL/12'>'>
    Last edited by dclamp; Nov 21st, 2008 at 08:44 PM.
    My usual boring signature: Something

  6. #6
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Secret Location For Pictures?

    Nice catch dclamp. I didn't even notice the URL was in an img tag, I had assumed it was in a hyperlink anchor.

    If dclamp's solution doesn't work for you, give us the HTML code your incorrect page displays.

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Secret Location For Pictures?

    Two points, one trivial, one not so trivial:

    (1) Don't use echo to write HTML. PHP is designed to be embedded within HTML not vice versa.

    (2) Never echo back input that comes from the client. This is called a cross-site scripting (XSS) vulnerability. Why?— because you are outputting user input without validating it, anyone can manipulate the query string component of the URL to inject malicious JavaScript into the page and potentially gain unauthorised access to data, such as through reading other users' cookies.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: Secret Location For Pictures?

    I tested all possible codes, but none of them worked!!!
    Isn't there a secure way to do that, not necessarly by the same idea. I just want to unable the user to see the real location of the image
    thank's

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width