emehrkay Posted March 9, 2007 Share Posted March 9, 2007 i have about twenty files that i want to include in a single script, any way to do this with a single line of code? Quote Link to comment https://forums.phpfreaks.com/topic/42000-is-there-a-way-to-include-all-of-the-files-in-a-directory/ Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 Best bet is to read up here: http://us2.php.net/manual/en/class.dir.php Have fun! --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42000-is-there-a-way-to-include-all-of-the-files-in-a-directory/#findComment-203654 Share on other sites More sharing options...
emehrkay Posted March 9, 2007 Author Share Posted March 9, 2007 thanks ill look into looping with that Quote Link to comment https://forums.phpfreaks.com/topic/42000-is-there-a-way-to-include-all-of-the-files-in-a-directory/#findComment-203677 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 No problem, maybe once you figure it out post that code, I would be interested to see what you came up with. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/42000-is-there-a-way-to-include-all-of-the-files-in-a-directory/#findComment-203681 Share on other sites More sharing options...
Orio Posted March 9, 2007 Share Posted March 9, 2007 If you got php5: <?php $dir = "includes/"; $cont = scandir($dir); foreach ($cont as $file) { if(is_file($file)) include($file); } ?> If you have php4, add this function the the code: <?php function php4_scandir($dir,$listDirectories=false, $skipDots=true) { $dirArray = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if (($file != "." && $file != "..") || $skipDots == true) { if($listDirectories == false) { if(is_dir($file)) { continue; } } array_push($dirArray,basename($file)); } } closedir($handle); } return $dirArray; } ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/42000-is-there-a-way-to-include-all-of-the-files-in-a-directory/#findComment-203695 Share on other sites More sharing options...
emehrkay Posted March 9, 2007 Author Share Posted March 9, 2007 thanks orio this is what i took directly from the site with a slight modification <?php /** * requre all of the schema files */ if($handle = opendir(CLASS_PATH.'ertool/schema/')){ while(false !== ($file = readdir($handle))) { if($file != '.' && $file != '..'){ require_once(CLASS_PATH. 'ertool/schema/'. $file); } } closedir($handle); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/42000-is-there-a-way-to-include-all-of-the-files-in-a-directory/#findComment-203711 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.