Gallery from folder whit php


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $thumb = "thumb"; //thumb folder name whit no "/"
  3. $images = "img"; //images folder name whit no "/"
  4.  
  5.  
  6. $listOfFilesToSort = array();
  7. $folder = opendir($images);
  8. while ( false !== ( $file = readdir( $folder ))){
  9. if ( $file != "." && $file != ".." )
  10. $listOfFilesToSort[$file] = $file;
  11. }
  12. sort( $listOfFilesToSort );
  13. foreach ( $listOfFilesToSort as $file )
  14. {
  15. echo '<a href="'.$images.'/'.$file.'"><img src="'.$thumb.'/'.$file.'" class="gal"></a>';
  16. }
  17. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.