Jump to content
Sign in to follow this  
codeminer

Auto Registering Files

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 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 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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  . 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×