Craig Hopson Posted April 24, 2012 Share Posted April 24, 2012 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 More sharing options...
birbal Posted April 24, 2012 Share Posted April 24, 2012 $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 More sharing options...
Craig Hopson Posted April 25, 2012 Author Share Posted April 25, 2012 Thanks for the Quick simple responce but it didn't work i just get broken link photos as if the $file variable is empty any ideas? Link to comment Share on other sites More sharing options...
Craig Hopson Posted April 25, 2012 Author Share Posted April 25, 2012 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.