blueman378 Posted October 26, 2008 Share Posted October 26, 2008 hi guys, im using a windows machine xp. im trying to write some code to include all files from a directory. so i have my index.php i also have a directory called plugins. heres my code: <?php if ($handle = opendir('plugins/')) { echo "<!--included plugins:-->"; while (false !== ($file = readdir($handle))) { if($file != "." && $file != "..") echo "<!--$file-->\n"; include_once("plugins/$file"); ?> } but im getting: Warning: include_once(plugins\.) [function.include-once]: failed to open stream: Permission denied in C:\wamp\www\Smarty Forum\index.php on line 76 Warning: include_once() [function.include]: Failed opening 'plugins\.' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\Smarty Forum\index.php on line 76 Warning: include_once(plugins\..) [function.include-once]: failed to open stream: Permission denied in C:\wamp\www\Smarty Forum\index.php on line 76 Warning: include_once() [function.include]: Failed opening 'plugins\..' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\Smarty Forum\index.php on line 76 any ideas? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 26, 2008 Share Posted October 26, 2008 You're trying to include . (because your if statement doesn't have brackets) which is causing the problem. if($file != "." && $file != "..") echo "<!--$file-->\n"; include_once("plugins/$file"); should be if($file != "." && $file != "..") { echo "<!--$file-->\n"; include_once("plugins/$file"); } Quote Link to comment Share on other sites More sharing options...
Andy-H Posted October 26, 2008 Share Posted October 26, 2008 while (false !== ($file = readdir($handle))){ Shouldn't that be while (($file = readdir($handle)) !== false){ Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 26, 2008 Share Posted October 26, 2008 while (false !== ($file = readdir($handle))){ Shouldn't that be while (($file = readdir($handle)) !== false){ same thing Quote Link to comment Share on other sites More sharing options...
blueman378 Posted October 26, 2008 Author Share Posted October 26, 2008 although on php freaks doesnt it say one way is better? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 26, 2008 Share Posted October 26, 2008 it's really personal preference. I've seen professional programmers do if(1 < i && i < 5) { if(i > 1 && i < 5) { if(null === ($something)) { etc.. it's another one of those things like variable and method naming, as long as you're consistent there's nothing wrong with doing it either way. 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.