Jump to content

$handle = opendir PHOTO VIEWER limit to 5


Craig Hopson
 Share

Recommended Posts

Hi i'm using this code to display photos from a folder how can i limit to only 5 photos?

$handle = opendir(dirname(realpath(__FILE__)).'/uploads/'.$id.'/');		while($file = readdir($handle)){			if($file !== '.' && $file !== '..' && $file !== 'index.html'){				echo '<a href="uploads/'.$id.'/'.$file.'"><img src="uploads/'.$id.'/'.$file.'" border="0" style="padding:10px;" height="100px" width="100px" /></a>';			}		}

Thanks

Edited by Craig Hopson
Link to comment
Share on other sites

$handle = opendir(dirname(realpath(__FILE__)).'/uploads/'.$id.'/');$num=0;		while($file = readdir($handle)&&$num<6){		   ++$num;			if($file !== '.' && $file !== '..' && $file !== 'index.html'){				echo '<a href="uploads/'.$id.'/'.$file.'"><img src="uploads/'.$id.'/'.$file.'" border="0" style="padding:10px;" height="100px" width="100px" /></a>';			}		}

Edited by birbal
  • Like 1
Link to comment
Share on other sites

i got it working like this is this code acceptable?

$handle = opendir(dirname(realpath(__FILE__)).'/uploads/'.$id.'/');$num = 0;  while($file = readdir($handle)){  if($num < 7){  ++$num;      if($file !== '.' && $file !== '..' && $file !== 'index.html'){    echo '<a href="uploads/'.$id.'/'.$file.'"><img src="uploads/'.$id.'/'.$file.'" border="0" style="padding:10px;" height="100px" width="100px" /></a>';   }  }  }}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...