m_tyhurst2002 Posted December 7, 2010 Share Posted December 7, 2010 Hey guys, I have a folder which has images. In this folder there are images that start with "refl_". I want to make sure those are not displayed. This is what I tried and it does not work. I want to show all images that don't start with "refl_". I am new to this as I am sure some can see. Thanks for the help if possible! <?php $dir = opendir("img/portfolio/"); while (false !== ($file = readdir($dir))) { $pos = strpos($file, "refl_"); if ($pos == false) { echo '<img src="img/portfolio/' . $file . '" longdesc="img/portfolio/' . $file . '" /></a>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/220896-display-images-in-directory-that-begin-with-refl_/ Share on other sites More sharing options...
requinix Posted December 7, 2010 Share Posted December 7, 2010 Read the manual page for strpos to understand how it works. Once you've done that, ditch your current code and use glob instead. Link to comment https://forums.phpfreaks.com/topic/220896-display-images-in-directory-that-begin-with-refl_/#findComment-1143876 Share on other sites More sharing options...
m_tyhurst2002 Posted December 7, 2010 Author Share Posted December 7, 2010 Thanks, glob() was able to do it all kind of. Changed file names for the ones that I want shown to have "www_" at the begining. <?php $dir = "img/portfolio/www_*"; foreach (glob($dir) as $file) { echo '<img src="' . $file . '" longdesc="' . $file . '" width="800" height="481" />'; } ?> I am trying to learn... I guess I wouldn't need to closedir() if I didn't opendir() right, since I am using glob()? Thanks Link to comment https://forums.phpfreaks.com/topic/220896-display-images-in-directory-that-begin-with-refl_/#findComment-1144094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.