Jump to content

code generates "." and ".." before expected result


blueman378

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.