Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function containsPhpFile($fileName, $dir = './src/php')
- {
- $result = -1;
- $scan = scandir($dir);
- foreach ($scan as $main_file) {
- if ($result != -1) continue;
- if (in_array($main_file, array(".", ".."))) continue;
- $main_path = "$dir/$main_file";
- $sub_path = "";
- $sub_path_opened = array();
- if (is_dir($main_path)) {
- $scan_subpath = scandir($main_path);
- back: foreach ($scan_subpath as $sub_file) {
- if ($result != -1) continue;
- if (in_array($sub_path_opened, array($sub_path))) continue;
- if (in_array($sub_file, array(".", ".."))) continue;
- if (is_dir("$main_path/$sub_file")) {
- $sub_path = "$main_path/$sub_file";
- $_resultCompare = compareFile($fileName, $sub_path);
- if ($_resultCompare[0] !== -1 && $_resultCompare[0] !== 1) {
- $sub_path = "$sub_path/$_resultCompare[1]";
- $scan_subpath = scandir($sub_path);
- goto back;
- };
- array_push($sub_path_opened, $sub_path);
- $sub_path = str_replace("/$sub_file", "", $sub_path);
- if ($_resultCompare[0] === 1) $result = $_resultCompare[1];
- } elseif (is_dir("$sub_path/$sub_file")) {
- $sub_path = "$sub_path/$sub_file";
- $_resultCompare = compareFile($fileName, $sub_path);
- if ($_resultCompare[0] !== -1 && $_resultCompare[0] !== 1) {
- $sub_path = "$sub_path/$_resultCompare[1]";
- $scan_subpath = scandir($sub_path);
- goto back;
- };
- array_push($sub_path_opened, $sub_path);
- $sub_path = str_replace("/$sub_file", "", $sub_path);
- if ($_resultCompare[0] === 1) $result = 1;
- } else {
- if ("$sub_path/$sub_file" == "$sub_path/$fileName") $result = "$main_path/$fileName";
- }
- }
- } else {
- if ("$main_path/$main_file" == "$main_path/$fileName") $result = "$main_path/$fileName";
- }
- }
- return $result;
- }
- function compareFile($file, $path): array
- {
- $scan = scandir($path);
- $result = array(0 => -1);
- foreach ($scan as $_file) {
- if ($result[0] != -1) continue;
- if (in_array($_file, array(".", ".."))) continue;
- if (is_file("$path/$_file")) {
- if ("$path/$_file" == "$path/$file") $result = array(0 => 1, 1 => "$path/$file");
- } else $result = array(0 => 0, 1 => "$file");;
- }
- return $result;
- }
Add Comment
Please, Sign In to add comment