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? Link to comment https://forums.phpfreaks.com/topic/130144-solved-permission-denied-on-localhost/ 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"); } Link to comment https://forums.phpfreaks.com/topic/130144-solved-permission-denied-on-localhost/#findComment-674874 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){ Link to comment https://forums.phpfreaks.com/topic/130144-solved-permission-denied-on-localhost/#findComment-674877 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 Link to comment https://forums.phpfreaks.com/topic/130144-solved-permission-denied-on-localhost/#findComment-674879 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? Link to comment https://forums.phpfreaks.com/topic/130144-solved-permission-denied-on-localhost/#findComment-674893 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. Link to comment https://forums.phpfreaks.com/topic/130144-solved-permission-denied-on-localhost/#findComment-675016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.