Jump to content

$handle = opendir PHOTO VIEWER limit to 5


Craig Hopson

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

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>';			}		}

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...