View Full Version : one file based image viewer?
sakib000
Jun 10th 2007, 10:48 am
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
CygnetGames
Jun 10th 2007, 12:44 pm
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]' />";
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.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.