Skip to content
Advertisement

How can I check if specific file be used in php project and linux environment

Currently I want to check if a specific file be used in php project

$target = "foobar.php";
$ beUsed = checkFile($target);
  
function checkFile($target){
    //code to check be here
    if (beUsed) return true;
    return false;
}

thanks for reading, any help would be appreciated

Advertisement

Answer

You can use linux command

$target = "foobar.php";

searchFile($target);


function searchFile($target){
    $file_name = basename(__FILE__);

    $cmd = sprintf("grep -r --exclude='%s' %s ./* ",$file_name, $target);

    $res = exec($cmd);

    if($res){
        echo "Exists!" . PHP_EOL;

        print_r($res);

        return true;
    }

    return false;
}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement