ferrarisp

LARAVEL_busca_arq_pasta

Apr 6th, 2020
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function containsPhpFile($fileName, $dir = './src/php')
  2. {
  3.     $result = -1;
  4.     $scan = scandir($dir);
  5.     foreach ($scan as $main_file) {
  6.         if ($result != -1) continue;
  7.         if (in_array($main_file, array(".", ".."))) continue;
  8.         $main_path = "$dir/$main_file";
  9.         $sub_path = "";
  10.         $sub_path_opened = array();
  11.         if (is_dir($main_path)) {
  12.             $scan_subpath = scandir($main_path);
  13.             back: foreach ($scan_subpath as $sub_file) {
  14.                 if ($result != -1) continue;
  15.                 if (in_array($sub_path_opened, array($sub_path))) continue;
  16.                 if (in_array($sub_file, array(".", ".."))) continue;
  17.                 if (is_dir("$main_path/$sub_file")) {
  18.                     $sub_path = "$main_path/$sub_file";
  19.                     $_resultCompare = compareFile($fileName, $sub_path);
  20.                     if ($_resultCompare[0] !== -1 && $_resultCompare[0] !== 1) {
  21.                         $sub_path = "$sub_path/$_resultCompare[1]";
  22.                         $scan_subpath = scandir($sub_path);
  23.                         goto back;
  24.                     };
  25.                     array_push($sub_path_opened, $sub_path);
  26.                     $sub_path = str_replace("/$sub_file", "", $sub_path);
  27.                     if ($_resultCompare[0] === 1) $result = $_resultCompare[1];
  28.                 } elseif (is_dir("$sub_path/$sub_file")) {
  29.                     $sub_path = "$sub_path/$sub_file";
  30.                     $_resultCompare = compareFile($fileName, $sub_path);
  31.  
  32.                     if ($_resultCompare[0] !== -1 && $_resultCompare[0] !== 1) {
  33.                         $sub_path = "$sub_path/$_resultCompare[1]";
  34.                         $scan_subpath = scandir($sub_path);
  35.                         goto back;
  36.                     };
  37.                     array_push($sub_path_opened, $sub_path);
  38.                     $sub_path = str_replace("/$sub_file", "", $sub_path);
  39.                     if ($_resultCompare[0] === 1) $result = 1;
  40.                 } else {
  41.                     if ("$sub_path/$sub_file" == "$sub_path/$fileName") $result = "$main_path/$fileName";
  42.                 }
  43.             }
  44.         } else {
  45.             if ("$main_path/$main_file" == "$main_path/$fileName") $result = "$main_path/$fileName";
  46.         }
  47.     }
  48.     return $result;
  49. }
  50.  
  51. function compareFile($file, $path): array
  52. {
  53.     $scan = scandir($path);
  54.     $result = array(0 => -1);
  55.     foreach ($scan as $_file) {
  56.         if ($result[0] != -1) continue;
  57.         if (in_array($_file, array(".", ".."))) continue;
  58.         if (is_file("$path/$_file")) {
  59.             if ("$path/$_file" == "$path/$file") $result = array(0 => 1, 1 => "$path/$file");
  60.         } else $result = array(0 => 0, 1 => "$file");;
  61.     }
  62.     return $result;
  63. }
Add Comment
Please, Sign In to add comment