php - List specific directory and show image -


i have 2 php files trying combine: first.php file lists contents of specific directory. second.php file able show images of specific directory.

what try do: want list directory "camera/images". on click on link, images of directory should display.

below code lists directory "camera/images" , results this. - album1 - album2 - album3

every album contains images, link "first.php" , display contained images.

first.php

<?php $dir = opendir('camera/images');  echo '<ul>';  while ($read = readdir($dir))  {  if ($read!='.' && $read!='..')  {  echo '<li><a href="camera/images/'.$read.'">'.$read.'</a></li>';  }  }  echo '</ul>';  closedir($dir);  ?> 

second.php

<?php $files = glob("camera/images/*.*"); ($i=0; $i<count($files); $i++) { $num = $files[$i]; echo '<img src="'.$num.'" alt="random image" />'."<br><br>"; } ?> 

any ideas? thank you!

what try do: want list directory "camera/images". on click on link, images of directory should display.

if want occur without having refresh page going need use javascript. , if want image retrieved @ time clicked need use ajax call.

the simple answer overview: use jquery library. if familiar javascript can in normal javascript recommend jquery cross compatibility , general awesomeness.

you need generate page way want shown if had been clicked. need make sure div around images hidden. need bind click event each link , unhide div associated with.

here example can you.

i hope points in right direction.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -