Click here to Skip to main content
14,271,512 members
Rate this:
Please Sign up or sign in to vote.
See more:
I want show images on button's click event one by one.. i am using following piece of code to get name of images stored in a folder... this piece of code displays all images on a page.. but i want to show one image at a time and want to show next on button's click....

the code is


$files = glob("MyPP/*.*");

 for ($i=0; $i<count($files)-1; $i++)

 { $num = $files[$i];
//I want to call this statement on button's click event
   echo '<img src="'.$num.'" alt="random image" />'."<br /><br />";



Please guide me how i do it...

Thanks in advance

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can't do that in PHP...

PHP runs in the server and has no idea of the client's side.

Clicking a button and reacting to it must be done using forms.

You could do something like:
<form name='FormName' action='PHP_FILE_TO_EXEC.php' method='POST' enctype='application/x-www-form-urlencoded' onsubmit='return JS_FUNCTION();'>

If JS_FUNCTION is never returning TRUE then you will have created an event that will be running in javascript (you'll have called the JS_FUNCTION each time you will press the button.

Another thing you can do is to call the same PHP file you are in but with some parameters passed in the POST...

Hope this helps...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100