Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Brunoc4

Mudar Diretório PHP

Recommended Posts

Boa Tarde Galera,

 

Achei esse script na internet, e gostaria de saber onde nele eu mudo o nome da pasta que quero procurar os arquivos.

Segue script abaixo:

 

<!DOCTYPE HTML>
<html lang="sv">
<head>

</head>
<body>

<?php

$buttonvalue = "Search";
$search_at = "Search on";
$search_result = "gave this result";
$pages = "Number of pages with hits";
$to_small = "At least two characters is required";
$recursive = true;  // Change to false if no searching should be done in subdirectories.

//---------------------------- Do not change anything below this line -------------------------------------------------------------------------------

$html = <<<HTML
<p><br /></p>
<form name="form" action="">
<input type="text" name="search" size="30" /> 
<input type="button" value="$buttonvalue" 
 onclick='window.location.assign(document.URL.substring(0,document.URL.indexOf("?")) + "?search=" + document.form.search.value.replace(/ /g,"%20"))' />
</form>
HTML;

echo $html;

function textpart($body, $search) {
// Displays the text after the title
  $length = 30;
  $text = substr($body, max(stripos($body,$search) - $length, 0), strripos($body,$search) - stripos($body,$search) + strlen($search) + 2 * $length);
  if (strripos($text, " ") < strripos($text,$search)) {
    $text = $text . " ";
  }
  if (stripos($text, " ") != strripos($text, " ")) {
    $text = substr($text, stripos($text, " "), strripos($text, " ") - stripos($text, " "));
  }
  $temp = $text;
  $stop = substr($text, strripos($text, $search) + strlen($search));
  if (strlen($stop) > $length) {
    $stop = substr($text, strripos($text, $search) + strlen($search), $length);
    $stop = substr($stop, 0, strripos($stop, " "));
  }
  $text = "... ";
  while (stripos($temp,$search)) {
    $temp = substr_replace($temp, "<b>", stripos($temp, $search), 0);
    $temp = substr_replace($temp, "</b>", stripos($temp, $search) + strlen($search), 0);
    $text = $text . substr($temp, 0, stripos($temp, "</b>") + 4);
    $temp = substr($temp, stripos($temp, "</b>") + 4);
    if(stripos($temp, $search) > (2 * $length)) {
       $text = $text . substr($temp, 0, $length);
       $text = substr($text, 0, strripos($text, " ")) . " ... ";
       $temp = substr($temp, stripos($temp, $search) - $length);
       $temp = substr($temp, stripos($temp, " "));
    }
  }
  $text = $text . $stop . " ... ";
  echo $text; 
  return;
}

function compress($string, $first, $last) {
// Removes everything in $string from $first to $last including $first and $last
  while(stripos($string,$first) && stripos($string,$last)) {
    $string = substr_replace($string, "", stripos($string,$first), stripos($string,$last) - stripos($string,$first) + strlen($last));
  }
  return $string;  
}

function directoryToArray($directory, $recursive) {
// This function by XoloX was downloaded from http://snippets.dzone.com/user/XoloX
  $array_items = array();
  if ($handle = opendir($directory)) {
    while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != "..") {
        if (is_dir($directory. "/" . $file)) {
          if($recursive) {
            $array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive));
          }
        } else {
          $file = $directory . "/" . $file;
          $array_items[] = preg_replace("/\/\//si", "/", $file);
        }
      }
    }
    closedir($handle);
  }
  return $array_items;
}

function filewalk($file, $search, $counter, $webpath) {
// Selects and treats files with the extension .htm and .html and .asp and .php
  if (strtolower(substr($file, stripos($file, ".htm"))) == ".htm"
      || strtolower(substr($file, stripos($file, ".html"))) == ".html"
      || strtolower(substr($file, stripos($file, ".asp"))) == ".asp"
      || strtolower(substr($file, stripos($file, ".php"))) == ".php") {
    $all = file_get_contents($file);
    $body = substr($all, stripos($all,"<body"),stripos($all,"</body>") - stripos($all,"<body"));
    $body = preg_replace('/<br \/>/i', ' ', $body);
    $body = preg_replace('/<br>/i', ' ', $body);
    $body = compress($body,"<noscript","</noscript>");
    $body = compress($body,"<script","</script>");
    $body = compress($body,"<iframe","</iframe>");
    $body = compress($body,"<noframe","</noframe>");
    $body = strip_tags($body);
    $body = html_entity_decode($body, ENT_QUOTES);
    $body = preg_replace('/\s+/', ' ', $body);
    // Scans and displays the results
    if (stripos($body, $search)) {
      $title = substr($all, stripos($all,"<title>") + 7,stripos($all,"</title>") - stripos($all,"<title>") - 7);
      $title = html_entity_decode($title, ENT_QUOTES);
      $title = preg_replace('/\s+/', ' ', $title); 
      echo '<p><a href="' . $file . '">' . $title . '</a></br>';
      echo '<span id="webpath">' . $webpath . substr($file, stripos($file, "/")) . '</span><br />';
      echo textpart($body, $search) . '</p>';
      $counter = $counter + 1;
    }
  }
  return $counter;
}

// Reads the search text from the page's URL
$url = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
$url .= $_SERVER['SERVER_PORT'] != '80' ? $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"] : $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

if (stripos($url,"?search=")) $search = $_GET['search'];

$webpath = dirname($url);

// Starts searching
if (strlen($search) < 2 && trim($search) <> "") {
  echo '<p>' . $to_small . '!</p>';
  $search = "";
}

if (trim($search) <> "") {
  echo "<p>" . $search_at . " '<b>" . $search . "</b>' " . $search_result . ".</p>";
  $counter = 0;
  // Path to the folder containing this file
  $curdir = getcwd();
  // Opens the folder and read its contents
  if ($dir = opendir($curdir)) {
    $files = directoryToArray("./", $teste;
    foreach ($files as $file) {
      $counter = filewalk($file, $search, $counter, $webpath);
    }
    closedir($dir);
  }
  echo "<p>" . $pages . ": " . $counter . "</p>";
}
?>

</body>
</html>
Obrigado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara, você vai ter muitas dores de cabeça, pois se não sabe nem onde mudar o nome do diretório imagine o resto.

 

O quê você consegue entender desse código?

Estude melhor e vá testando, senão você não vai aprender a trabalhar com PHP e será totalmente dependente dos outros.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Amigão em momento algum falei que não entendo nada do código, mais sim gostaria de tirar uma dúvida. Afinal o fórum ta ai pra isso!

Compartilhar este post


Link para o post
Compartilhar em outros sites

  • Conteúdo Similar

    • Por violin101
      Caros amigos, saudações.
       
      Por favor, me permita tirar uma dúvida com os amigos.

      Tenho um Formulário onde o Usuário digita todos os Dados necessários.

      Minha dúvida:
      --> como faço após o usuário digitar os dados e salvar, o Sistema chamar uma Modal ou mensagem perguntando se deseja imprimir agora ?

      Grato,
       
      Cesar
    • Por Carcleo
      Tenho uma abela de usuarios e uma tabela de administradores e clientes.
      Gostaria de uma ajuda para implementar um cadastro
       
      users -> name, login, passord (pronta) admins -> user_id, registratiom, etc.. client -> user_id, registratiom, etc...
      Queria ajuda para extender de user as classes Admin e Client
      Olhem como estáAdmin
      <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Admin extends User {     use HasFactory;            protected $fillable = [         'name',         'email',         'password',         'registration'     ];      private string $registration;     public function create(         string $name,          string $email,          string $password,         string $registration     )     {         //parent::create(['name'=>$name, 'email'=>$email, 'password'=>$password]);         parent::$name = $name;         parent::$email = $email;         parent::$password = $password;         $this->registration = $registration;     } } User
      <?php namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Database\Eloquent\Relations\BelongsToMany; class User extends Authenticatable {     /** @use HasFactory<\Database\Factories\UserFactory> */     use HasFactory, Notifiable;     static string $name;     static string $email;     static string $password;     /**      * The attributes that are mass assignable.      *      * @var list<string>      */     protected $fillable = [         'name',         'email',         'password',     ];          /**      * The attributes that should be hidden for serialization.      *      * @var list<string>      */     protected $hidden = [         'remember_token',     ];     /**      * Get the attributes that should be cast.      *      * @return array<string, string>      */     protected function casts(): array     {         return [             'email_verified_at' => 'datetime',             'password' => 'hashed',         ];     }          public function roles() : BelongsToMany {         return $this->belongsToMany(Role::class);     }       public function hasHole(Array $roleName): bool     {                 foreach ($this->roles as $role) {             if ($role->name === $roleName) {                 return true;             }         }         return false;     }         public function hasHoles(Array $rolesName): bool     {                 foreach ($this->roles as $role) {             foreach ($rolesName as $rolee) {             if ($role->name === $rolee) {                 return true;             }          }         }         return false;     }         public function hasAbility(string $ability): bool     {         foreach ($this->roles as $role) {             if ($role->abilities->contains('name', $ability)) {                 return true;             }         }         return false;     }     } Como gravar um Admin na tabela admins sendo que ele é um User por extensão?
      Tentei assim mas é claro que está errado...
      public function store(Request $request, Admin $adminModel) {         $dados = $request->validate([             "name" => "required",             "email" => "required|email",             "password" => "required",             "registration" => "required"         ]);         $dados["password"] =  Hash::make($dados["password"]);                  $admin = Admin::where("registration",  $dados["registration"])->first();                  if ($admin)              return                    redirect()->route("admin.new")                             ->withErrors([                                 'fail' => 'Administrador já cadastrados<br>, favor verificar!'                   ]);                            $newAdmin = $adminModel->create(                                    $dados['name'],                                    $dados['email'],                                    $dados['password'],                                    $dados['registration']                                 );         dd($newAdmin);         $adminModel->save();         //$adminModel::create($admin);                  return redirect()->route("admin.new")->with("success",'Cadastrado com sucesso');     }  
    • Por violin101
      Caros amigos, saudações.
       
      Gostaria de tirar uma dúvida com os amigos, referente a PDV.
       
      Estou escrevendo um Sistema com Ponto de Vendas, a minha dúvida é o seguinte, referente ao procedimento mais correto.

      Conforme o caixa vai efetuando a venda, o Sistema de PDV já realiza:
      a baixa direto dos produtos no estoque
      ou
      somente após concretizar a venda o sistema baixa os produtos do estoque ?
       
      Grato,
       
      Cesar
       
    • Por violin101
      Caros amigos do grupo, saudações e um feliz 2025.
       
      Estou com uma pequena dúvida referente a Teclas de Atalho.

      Quando o Caps Lock está ativado o Comando da Tecla de Atalho não funciona.
      ou seja:
      se estiver para letra minúscula ====> funciona
      se estiver para letra maiúscula ====> não funciona
       
      Como consigo evitar essa falha, tanto para Letra Maiúscula quanto Minúscula ?

      o Código está assim:
      document.addEventListener( 'keydown', evt => { if (!evt.ctrlKey || evt.key !== 'r' ) return;// Não é Ctrl+r, portanto interrompemos o script evt.preventDefault(); });  
      Grato,
       
      Cesar
    • Por violin101
      Caros amigos, saudações.
       
      Por favor, poderiam me ajudar.

      Estou com a seguinte dúvida:
      --> como faço para para implementar o input código do produto, para quando o usuário digitar o ID o sistema espera de 1s a 2s, sem ter que pressionar a tecla ENTER.

      exemplo:
      código   ----   descrição
           1       -----   produto_A
       
      Grato,
       
      Cesar
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.