blueman378 Posted March 4, 2008 Share Posted March 4, 2008 hi guys well i have this code here, // Retrieve Sections $dirpath = "{$root}sections"; $sectionListIgnore = array (''); $dh = opendir($dirpath); while (false !== ($file = readdir($dh)) && !in_array($file,$sectionListIgnore)) { include("{$root}sections/{$file}"); }closedir($dh); whick works like it should EXCEPT that it also generates two places which simply contain . and .. so i end up getting this error Warning: include() [function.include]: Failed opening 'Thissite/sections/.' for inclusion (include_path='.;C:\php5\pear') in C:\Documents and Settings\Matthew\My Documents\Web\index.php on line 23 Warning: include(Thissite/sections/..) [function.include]: failed to open stream: Permission denied in C:\Documents and Settings\Matthew\My Documents\Web\index.php on line 23 Warning: include() [function.include]: Failed opening 'Thissite/sections/..' for inclusion (include_path='.;C:\php5\pear') in C:\Documents and Settings\Matthew\My Documents\Web\index.php on line 23 and then all the sections after that load fine, any ideas why it generates those .'s? cheers matt Link to comment https://forums.phpfreaks.com/topic/94217-code-generates-and-before-expected-result/ Share on other sites More sharing options...
Stooney Posted March 4, 2008 Share Posted March 4, 2008 Those are just 'root' and 'up one level' (correct me if I'm wrong, but it's at least something close to that). They're normal, it doesn't mean there's a problem with your script, you just have to work around them. So just add something like: <?php if($file!='.' && $file!='..'){ include("{root}sections/{$file}"); } <?php Link to comment https://forums.phpfreaks.com/topic/94217-code-generates-and-before-expected-result/#findComment-482607 Share on other sites More sharing options...
blueman378 Posted March 4, 2008 Author Share Posted March 4, 2008 thats what i thought so i thought ok lets do this: $sectionListIgnore = array ('.','..'); but then nothing shows up at all? any ideas on that id rather use an array than a long if statement Link to comment https://forums.phpfreaks.com/topic/94217-code-generates-and-before-expected-result/#findComment-482618 Share on other sites More sharing options...
Stooney Posted March 4, 2008 Share Posted March 4, 2008 maybe try: while (false !== ($file = readdir($dh)) && !in_array(basename($file),$sectionListIgnore)) { (I won't be able to reply till tomorrow) Link to comment https://forums.phpfreaks.com/topic/94217-code-generates-and-before-expected-result/#findComment-482623 Share on other sites More sharing options...
blueman378 Posted March 4, 2008 Author Share Posted March 4, 2008 i have while (false !== ($file = readdir($dh)) && !in_array($file,$sectionListIgnore)) { which works if for example i have a file called image and i have image in the array, but not with the dots Link to comment https://forums.phpfreaks.com/topic/94217-code-generates-and-before-expected-result/#findComment-482626 Share on other sites More sharing options...
blueman378 Posted March 4, 2008 Author Share Posted March 4, 2008 got it, <?php // Retrieve modules $modulepath = "{$root}modules"; $sectionListIgnore = array ('.','..','template.module'); $dh = opendir($modulepath); while (false !== ($file = readdir($dh))) { if(!in_array($file,$sectionListIgnore)){ include("{$root}modules/{$file}"); } } closedir($dh); ?> because it was using while it meant that as soon as it got to a item in the array the while was then maked false so it stopped, it jsut so happend that . would come first so nothing would be outputted, so this works perfect Link to comment https://forums.phpfreaks.com/topic/94217-code-generates-and-before-expected-result/#findComment-482642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.