imdead Posted June 23, 2008 Share Posted June 23, 2008 Hey Peoples , I Made This For My Image Gallery <?php $thumbs = scandir('image'); foreach($thumbs as $thumb) { if(substr($thumb, 0, 1) !== '.') echo '<img src="image/', $thumb, '"/ width="200" height="200">'; echo '<a href="image/', $thumb, '"/>View Normal Size</a>'; } ?> And It's Displaying It How It Should Execpt I Get Two Extra Links At The Front That Link To The Image Dir And One Links To The Main Root. What Can You Guys Do? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 23, 2008 Share Posted June 23, 2008 Write your if() statement so that it has {} around the lines of code you only want to execute if the statement is true. Without any {}, only the single line following the if() statement is conditionally executed. Quote Link to comment Share on other sites More sharing options...
imdead Posted June 23, 2008 Author Share Posted June 23, 2008 Don't Worry I Fixed Them Links But Now, <?php $thumbs = scandir('image'); foreach($thumbs as $thumb) { if ($thumb[0]=='.') continue; if ($thumb[0]=='index.html') continue; echo '<img src="image/', $thumb, '"/ width="200" height="200">'; echo '<a href="image/', $thumb, '"/>View Normal Size</a>'; } ?> I Can't Make It Skip The Index.html file Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 23, 2008 Share Posted June 23, 2008 <?php $file_types = array('gif', 'jpg'); foreach(scandir('image') as $thumb) { if (is_file($thumb) && in_array(end(explode('.', $thumb)), $file_types)) { echo '<img src="image/', $thumb, '"/ width="200" height="200">'; echo '<a href="image/', $thumb, '"/>View Normal Size</a>'; } } ?> Quote Link to comment Share on other sites More sharing options...
imdead Posted June 23, 2008 Author Share Posted June 23, 2008 Thats Not Displaying Anything? Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 23, 2008 Share Posted June 23, 2008 There was some errors in the echo code. I fixed that and made it more modular. Try this: <?php $file_types = array('gif','jpg'); $directory = 'image'; foreach(scandir($directory) as $thumb) { if (is_file("$directory/$thumb") && in_array(end(explode('.', $thumb)), $file_types)) { echo "<img src=\"$directory/$thumb\" width=\"200\" height=\"200\">"; echo "<a href=\"$directory/$thumb\">View Normal Size</a>"; } } ?> Quote Link to comment Share on other sites More sharing options...
imdead Posted June 24, 2008 Author Share Posted June 24, 2008 Fixed Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.