codeminer Posted November 6, 2017 Share Posted November 6, 2017 Im wondering if there is a way to to automaticly register a php file , so it wont show up when reading a directory. Doing this || $file == "somefile.php" after ten or twenty time gets to be grievious Link to comment Share on other sites More sharing options...
justsomeguy Posted November 6, 2017 Share Posted November 6, 2017 You can either use glob and specify a pattern where it only gets the files you want, if there is such a pattern, or yeah just check each one. You don't have to copy and paste a bunch of conditions though, put all the filenames in an array and use in_array. Link to comment Share on other sites More sharing options...
codeminer Posted November 6, 2017 Author Share Posted November 6, 2017 i tried using this i add variables to create the characters || $ == "" i was able to wrap each file in the proper syntaxes when i call it on the script i kept getting those charming error messages. i dont know what a glob is i ll go look it up . thanks again <?php //like fopen/fread/fclose //opendir() //readdir() //closedir() $dir = "."; if(is_dir($dir)){ if($dir_handle = opendir($dir)){ while($filename = readdir($dir_handle)){ echo "filename:{$filename}<br/>"; } //closedir($dir_handle); //} //} echo "<hr/>"; //scandir():reads all file names into an array if(is_dir($dir)){ $dir_array = scandir($dir); foreach($dir_array as $file){ if(stripos($file, '.')> 0){ echo "filename:{$file}<br/>"; } } } closedir($dir_handle); } } ?> hanks i will try it Link to comment Share on other sites More sharing options...
justsomeguy Posted November 6, 2017 Share Posted November 6, 2017 There's a class specifically for this: http://php.net/manual/en/class.directoryiterator.php e..g: http://php.net/manual/en/directoryiterator.construct.php It implements an interface so that you can use foreach to loop through the directory. The list of methods on the right side of that page shows what you can do with each file (e.g. isDot, getFilename, etc). And if you want to have a list of files to skip, put all of those filenames in an array and use in_array to see if you should skip the current file. Link to comment Share on other sites More sharing options...
codeminer Posted November 7, 2017 Author Share Posted November 7, 2017 this has been very helpfull i been working on this all day i did check out the glob concept at php.net they have a lot of examples . i need to run some through the editor see what they do . i will all so check out your link . i would really like to come up with something i think it would benifit every one to have a tool like that. save a lot of time . Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now