php - How to exclude some files and extensions from indexing? -


i have code indexing directories , files on site, need exclude files (hidden_file.txt or hidden_folder) , extensions (.php example). how can that?

this code, has hide variable, don't know how change purpose:

 <?php // checks see if veiwing hidden files enabled if($_server['query_string']=="hidden") {$hide="";} else {$hide=".";}   // opens directory  $mydirectory=opendir(".");  // gets each entry while($entryname=readdir($mydirectory)) {    $dirarray[]=$entryname; }  // closes directory closedir($mydirectory);  // counts elements in array $indexcount=count($dirarray);  // sorts files sort($dirarray);  // loops through array of files for($index=0; $index < $indexcount; $index++) {  // decides if hidden files should displayed, based on query above.     if(substr("$dirarray[$index]", 0, 1)!=$hide) { // gets file names     $name=$dirarray[$index];     $namehref=$dirarray[$index]; $path =$_server['request_uri']; $nome= $_server['server_name'];  // output  echo("  <li><a class='color' href='$nome$path$namehref'>$name</a></li>");    } } ?> 

your $hide variable purpose hide every file name starting dot : "." , ".." , ".whatever" (current folder, parent folder, , hidden files) results.

// gets each entry while($entryname=readdir($mydirectory)) {    $ext = pathinfo($mydirectory . path_separator . $entryname, pathinfo_extension);    if(in_array($ext, array('php', 'secret', 'hidden'))){continue;} //here extension list don't want show    if(strpos(strtolower($entryname, 'hidden'))){continue;} //add rules want (this 1 means, if there "hidden" in filename, pass next file.    if(strpos(strtolower($entryname, 'secret'))){continue;}    $dirarray[]=$entryname; //if filename has passed rules gets added list. } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -