one file based image viewer?

Discussion in 'Programming' started by sakib000, Jun 10, 2007.

  1. #1
    I have lot of images to show on my site. I want to know how can i do this using one file something like viewer.php so that i can point link to example.com/viewer.php?=/images/myfile.jpg
     
    sakib000, Jun 10, 2007 IP
  2. CygnetGames

    CygnetGames Peon

    Messages:
    43
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use the GET methods of PHP.
    If you use a url such as: example.com/viewer.php?imagePath=/images/myfile.jpg
    Then the file "viewer.php" will be passed the value "/images/myfile.jpg" in the GET variable "imagePath".

    To access this in your PHP code, you need to use $_GET['imagePath']. _GET is an array containing all of the GET variables passed in to the page.

    So to include the image in your page, you would do something like:
    echo "<img src='$_GET[imagePath]' />";
    PHP:
    One thing to think about with using GET is that anyone using your site can type anything they want as a URL, so you might want to do some validation on your GET variables before using them, to avoid code injection attacks.
     
    CygnetGames, Jun 10, 2007 IP