<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);

$search = 'all_salary_monthly_get';
$dir = '/home/jobaajgroup/public_html/emp3.jobaaj.com';
// $folder = ['assets', 'siliconassets', 'will_delete', 'testgaurav', 'authority', 'minified', 'blogs', 'admin_panel', 'recruiter_services', 'pin', 'controller2'];

function scanDirectory($dir, $search)
{
    $files = scandir($dir);
    foreach ($files as $file) {
        if ($file === '.' || $file === '..') {
            continue;
        }

        // if ($dir=='/home/eshancollegemgmt/public_html/jobaaj.com/' && in_array($file, $GLOBALS['folder'])) {
        //     continue;
        // }

        $filePath = $dir . '/' . $file;
        if (is_dir($filePath)) {
            scanDirectory($filePath, $search); // Recursive call for inner directories
        } else {
            // if (strlen($file) > 3 && in_array(pathinfo($file, PATHINFO_EXTENSION), ['php'])) {
            if (strlen($file) > 3) {
            // if (strlen($file) > 3) {
                $readfile = fopen($filePath, 'r');

                while (!feof($readfile)) {
                    $contents = fgets($readfile);
                    if (stripos($contents, $search) !== false) {
                        // $fp = fopen("/home/eshancollegemgmt/public_html/jobaaj.com/jobaaj_cdn.txt", 'a');
                        // fwrite($fp, "$filePath\r\n");
                        // fclose($fp);
                        echo $filePath . "<br>\r\n";
                        break; // Stop reading the file once the search query is found
                    }
                }

                fclose($readfile);
            }
        }
    }
}

scanDirectory($dir, $search);
// echo "<pre>";
// print_r($_SERVER);
// echo "</pre>";
