|
Posted by OmegaJunior on 02/25/07 20:44
On Sun, 25 Feb 2007 21:10:57 +0100, shror <shahirwm@gmail.com> wrote:
> hi every body
> I need help please
>
> i have designed an image gallery of about 20 pictures and they are
> shown in thumb nail views and for viewing the largeer version of the
> images i have added a radio button and a push button, so that the user=
> choose the picture using the radio button and click on the push button=
> to open the larger version picture in another window, but my problem
> is that i know how to pass the selection to the second page but the
> problem is how to pass the selected picture not selected value.
>
> the first html page code is:
>
> <form method=3D"POST" action=3D"gallery.php">
> <input type=3D"radio" value=3D"V1" name=3D"nature">
> <p><input type=3D"radio" value=3D"V1" name=3D"nature"></p>
> <p><input type=3D"radio" value=3D"V1" name=3D"nature">
> </form>
>
>
> the gallery.php code is:
>
> <?php
> $image =3D $_POST['nature'];
> echo "$image"
> ?>
>
>
> my problem is that this way gives me the name of the radio button i
> select not the image so how i can make the image get shown not the
> radio button name (not V1)
>
>
> Thanks in advance for your help
>
> shror
>
I can see two methods to help you out in this case:
1) Alter your form: change the radio button names into the text "picture=
" =
and change the value of each radio button into the name of the actual =
picture, like so:
<form method=3D"post" action=3D"gallery.php">
<p><input type=3D"radio" value=3D"nature.jpg" name=3D"picture"></p>
<p><input type=3D"radio" value=3D"sun.jpg" name=3D"picture"></p>=
<p><input type=3D"radio" value=3D"snow.jpg" name=3D"picture"></p=
>
<p><input type=3D"submit" value=3D"Show me" name=3D"btnOK"></p>
</form>
That way, your gallery.php can read $_POST['picture'] and it'll give you=
"nature.jpg"
"sun.jpg"
"snow.jpg"
which you then can show using fopen() for instance.
This method however has a drawback: it'll show any file whose name is =
presented go the gallery.php, meaning that any person with ill intent =
could make it load any file at all. Thus there's a second method:
2) Alter your form and the gallery.php to use indexed picture numbers =
instead of picture names, like so:
<form method=3D"post" action=3D"gallery.php">
<p><input type=3D"radio" value=3D"1" name=3D"picture"></p>
<p><input type=3D"radio" value=3D"2" name=3D"picture"></p>
<p><input type=3D"radio" value=3D"3" name=3D"picture"></p>
<p><input type=3D"submit" value=3D"Show me" name=3D"btnOK"></p>
</form>
That way, your gallery.php can read $_POST['picture'] and it'll give you=
=
1, 2, or 3 respectively, which you can use in a routine as follows:
$arrPictures =3D array();
$arrPictures[1] =3D "nature.jpg";
$arrPictures[2] =3D "sun.jpg";
$arrPictures[3] =3D "snow.jpg";
$imageIndex =3D $_POST['picture'];
if (isset($arrPictures[$imageIndex])) {
if (file_exists($arrPictures[$imageIndex])) {
$imageFile =3D fopen($arrPictures[$imageIndex]);
echo $imageFile;
@fclose($imageFile);
}
}
Don't forget to set a mime-type header!
Hope this helps!
-- =
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
[Back to original message]
|