insertMode=$insertMode; $this->strDirectory = $strDirectory; $this->arrFileExt = $arrFileExt; $this->boolTraverse = $boolTraverse; $this->arrPatern = $arrPatern; $this->crawlDirectory($this->strDirectory); } function findMatches($file) { /* * @Description: Compares the content of the file through the patterns. * * @Method: findMatches * @Parameters: 1 * @Param-1: file - String - The full path of the file to be checked * @return - Boolean - If Successfully read or not * */ if($fp = @fopen($file, "r")) { $data = fread($fp, filesize($file)); fclose($fp); $pattern="'" . implode("|",$this->arrPatern) . "'"; if(preg_match($pattern,$data)) { if($this->insertMode) return false; else return true; } else { if($this->insertMode) return true; else return false; } } else { $this->arrErrFilesAndDirectory[] = $file; return false; } } function crawlDirectory($strDirectory) { /* * @Description: Browse the file content of a directory path * * @Method: crawlDirectory * @Parameters: 1 * @Param-1: strDirectory - String - The directory path to be searched * @retuns: Nothing * */ //checks if the arrBlackListedPattern and arrFileType is supplied with proper array values if(is_array($this->arrPatern) && is_array($this->arrFileExt)) { //this opens the directory up if($dirHandle = opendir($strDirectory)) { $this->strPathDivider = substr(PHP_OS, 0, 3) == "WIN" ? "\\" : "/"; //browse the files in the directory while (false !== ($strFile = readdir($dirHandle))) { if($strFile <> '.' AND $strFile <> '..') { $strFullFilePath = $strDirectory.$this->strPathDivider.$strFile; if($this->boolTraverse AND is_dir($strFullFilePath)) { $this->crawlDirectory($strFullFilePath); } else { $arrFileParts = explode(".", $strFile); $arrFileParts = array_reverse($arrFileParts); $strFileExt = $arrFileParts[0]; if(in_array($strFileExt, $this->arrFileExt)) { if($this->findMatches($strFullFilePath)) { $this->arrMatchedFiles[] = $strFullFilePath; } } } } } closedir($dirHandle); } else { $this->arrErrFilesAndDirectory[] = $strDirectory; } } else { //display should supply proper array values to the parameter $arrPatern and $arrFileExt } } } ?>