Ir para conteúdo
Fórum Script Brasil
  • 0

Nevegação em diretórios


Gabriel Koerich

Pergunta

Script interessante que permite a navegação nas pastas e arquivos do site. inclui o arquivo quando clicado, talvez tenha alguns erros. quis tentar fazer algo de editar os arquivos, mas ãtive tempo

Se instalado no computador, é possível entrar nas pastas do sistema e arquivos de programas, colocando a variavel ?dir=.., ?dir=../.., etc

dir.php

<?php
print '<title>Arquivos/Diretórios</title>';
$dir = $_GET['dir'];
$arquivo = $_GET['arquivo'];

if(!$dir && !$arquivo){     

    $dir = "."; 

}
print '<b>Pasta:</b> '; 
$raiz = end(explode("/", $_SERVER['DOCUMENT_ROOT']));
$pasta = explode("/", $dir);
if($dir && $dir !== "." && !$arquivo){    
    print '<a href="../">'.$raiz.'</a>/';        
    
    for($i = 0; $i < count($pasta); $i++){  
        if($open = opendir($dir)){      
            $d = $dir."/".$file;       
            
            if(is_dir($d)){    
                if($pasta[$i] == $pasta[0]){            
                    print '<a href=?dir='.$pasta[$i].'>'.$pasta[$i];        
                    print '</a>';        $link = "";    
                }elseif($pasta[$i] == $pasta[1]){        
                    print '/<a href=?dir='.$pasta[$i-1].'/'.$pasta[$i].'>'.$pasta[$i];        
                    print '</a>';        $link = $pasta[$i-1];    
                }elseif($pasta[$i] == $pasta[2]){        
                    print '/<a href=?dir='.$pasta[$i-2].'/'.$pasta[$i-1].'/'.$pasta[$i].'>'.$pasta[$i];        
                    print '</a>';        $link = $pasta[$i-2]."/".$pasta[$i-1];    
                }elseif($pasta[$i] == $pasta[3]){        
                    print '/<a href=?dir='.$pasta[$i-3].'/'.$pasta[$i-2].'/'.$pasta[$i-1].'/'.$pasta[$i].'>'.$pasta[$i];        
                    print '</a>';        
                    
                    $link = $pasta[$i-3]."/".$pasta[$i-2]."/".$pasta[$i-1];    
                    
                }elseif($pasta[$i] == $pasta[4]){        
                    print '/<a href=?dir='.$pasta[$i-4].'/'.$pasta[$i-3].'/'.$pasta[$i-2].'/'.$pasta[$i-1].'/'.$pasta[$i].'>'.$pasta[$i];        
                    print '</a>';        
                    
                    $link = $pasta[$i-4]."/".$pasta[$i-3]."/".$pasta[$i-2]."/".$pasta[$i-1];    
                }elseif($pasta[$i] == $pasta[5]){        
                    print '/<a href=?dir='.$pasta[$i-5].'/'.$pasta[$i-4].'/'.$pasta[$i-3].'/'.$pasta[$i-2].'/'.$pasta[$i-1].'/'.$pasta[$i].'>'.$pasta[$i];        
                    print '</a>';        
                    
                    $link = $pasta[$i-5]."/".$pasta[$i-4]."/".$pasta[$i-3]."/".$pasta[$i-2]."/".$pasta[$i-1];    
                }      
            }else{    
                print $dir;      
            }    
            
        }
        closedir($open);    
    }      
    
    $numero = count($pasta);  
    $anterior = $pasta[$numero-2];  
    $ant = $pasta[$numero-3];  
    print '<br><br';  
    print '<img src=icons/back.gif> <a href=?dir=';  
    print $link;  
    print '>Diretório Acima</a>';
}else{    
    print $raiz;
}
if($dir && !$arquivo){          
    print '<br><br><table width="400" border="0" cellspacing="0" cellpadding="0">      <tr>    <td width="229">        <strong>Arquivo/Diret&oacute;rio</strong>    </td>          <td width="171">        <strong>Tamanho</strong>    </td>        </tr>'; 
    }
    if(!$arquivo && $abre = opendir($dir)){    
        $x = 0;        
        while(($file = readdir($abre)) !== false){  
            $d = $dir."/".$file;   
            if(($file !== "." && $file !== ".." && is_dir($file)) OR ($file !== "." && $file !== ".." && is_dir($d))){      
                $x++;      
                $quebra = explode('.', $file);      
                $ext = strtolower(end($quebra));      
                $tam = @filesize($file);      
                $tamanho = @filesize($d);      
                print '<tr><td>';      
                print '<img src="icons/folder.gif" alt="[Diretório]"></img> ';            
                    if($dir !== "."){                
                        echo " <a href=?dir=".$dir."/".$file.">".$file."</a><br>";       
                    }else{    
                        echo " <a href=?dir=".$file.">".$file."</a><br>";       
                    }      
                    print'</tr></td>';  
            }        
                
        }   
        closedir($abre);
}    
if(!$arquivo && $abre = opendir($dir)){    
    $x = "0";    
    while(($file = readdir($abre)) !== false){  
        $d = $dir."/".$file;  
        if(($file !== "." && $file !== ".." && is_file($file)) OR ($file !== "." && $file !== ".." && is_file($d))){       
            $x++;      
            $quebra = explode('.', $file);            
            $ext = strtolower(end($quebra));      
            $tam = @filesize($file);      
            $tamanho = @filesize($d);            
            $diretorio[$x] = $file;      
            if($dir !== "."){    
                print '<tr><td>';    
                if ($quebra[0] == "index") {                    
                    echo "<img src=\"icons/index.gif\" border=\"0\" /> ";                
                }elseif($ext == "exe" || $ext == "msi"){                    
                    echo "<img src=\"icons/comp.gray.gif\" border=\"0\" /> ";                
                }elseif($ext == "php" || $ext == "asp" || $ext == "htm" || $ext == "html" || $ext == "shtml" || $ext == "phtml" || $ext == "css" || $ext == "htaccess" || $ext=="htacess"){                   
                    echo "<img src=\"icons/layout.gif\" border=\"0\" /> ";    
                }elseif($ext == "jpg" || $ext == "jpeg" || $ext == "gif" || $ext == "png" || $ext == "bmp"){                    
                    echo "<img src=\"icons/image2.gif\" border=\"0\" /> ";                
                }elseif($ext == "js" || $ext == "cgi"){                    
                    echo "<img src=\"icons/script.gif\" border=\"0\" /> ";                
                }elseif($ext == "mp3" || $ext == "asf" || $ext == "au" || $ext == "wav" || $ext == "mid"){                    
                    echo "<img src=\"icons/sound1.gif\" border=\"0\" /> ";                
                }elseif($ext == "mpg" || $ext == "mpeg" || $ext == "qt" || $ext == "wmv" || $ext == "mov" || $ext == "avi"){                    echo "<img src=\"icons/movie.gif\" border=\"0\" /> ";                
                }elseif($ext == "doc" || $ext == "txt" || $ext == "pdf"){                    
                    echo "<img src=\"icons/text.gif\" border=\"0\" /> ";                
                }elseif($ext == "zip" || $ext == "tar" || $ext == "arj" || $ext == "rar"){                    
                    echo "<img src=\"icons/compressed.gif\" border=\"0\" /> ";                
                }else{                    
                    echo "<img src=\"icons/unknown.gif\" border=\"0\" /> ";                
                }          
                print '<a href=?arquivo='.$file.'&dir='.$dir.'>'.$file.'</a></td>';        
                print '<td>';    
                if(!is_file($file)){        
                    if($tamanho < "1024"){      
                        echo number_format($tamanho, 0, ",", ".")." byte(s)<br>";        
                        }elseif($tamanho/1024 < 1024){      
                            echo number_format($tamanho/1024, 2, ",", ".")." KB<br>";        
                        }else{      
                            echo number_format($tamanho/(1024*1024), 2, ",", ".")." MB<br>";        
                        }        
                        print '</td></tr><td>';    
                    }else{        
                        if($tam < "1024"){      
                            echo number_format($tam, 0, ",", ".")." byte(s)<br>";        
                        }elseif($tamanho/1024 < "1024"){      
                            echo number_format($tam/1024, 2, ",", ".")." KB<br>";        
                        }else{      
                            echo number_format($tam/(1024*1024), 2, ",", ".")." MB<br>";        
                        }        
                        print '</td></tr>';    
                    }              
                }else{   
                    $tam = @filesize($file);    
                    $tamanho = @filesize($d);    
                    print '<tr><td>';        
                    if($quebra[0] == "index"){                    
                        echo "<img src=\"icons/index.gif\" border=\"0\" /> ";                
                    }elseif($ext == "exe" || $ext == "msi"){                    
                        echo "<img src=\"icons/comp.gray.gif\" border=\"0\" /> ";                
                    }elseif($ext == "php" || $ext == "asp" || $ext == "htm" || $ext == "html" || $ext == "shtml" || $ext == "phtml" || $ext == "css" || $ext == "htaccess" || $ext=="htacess"){                    
                        echo "<img src=\"icons/layout.gif\" border=\"0\" /> ";    
                    }elseif($ext == "jpg" || $ext == "jpeg" || $ext == "gif" || $ext == "png" || $ext == "bmp"){                    
                        echo "<img src=\"icons/image2.gif\" border=\"0\" /> ";                
                    }elseif($ext == "js" || $ext == "cgi"){                    
                        echo "<img src=\"icons/script.gif\" border=\"0\" /> ";                
                    }elseif($ext == "mp3" || $ext == "asf" || $ext == "au" || $ext == "wav" || $ext == "mid"){                    
                        echo "<img src=\"icons/sound1.gif\" border=\"0\" /> ";                
                    }elseif($ext == "mpg" || $ext == "mpeg" || $ext == "qt" || $ext == "wmv" || $ext == "mov" || $ext == "avi"){                        echo "<img src=\"icons/movie.gif\" border=\"0\" /> ";                
                    }elseif($ext == "doc" || $ext == "txt" || $ext == "pdf"){                    
                        echo "<img src=\"icons/text.gif\" border=\"0\" /> ";                
                    }elseif($ext == "zip" || $ext == "tar" || $ext == "arj" || $ext == "rar"){                    
                        echo "<img src=\"icons/compressed.gif\" border=\"0\" /> ";                
                    }else{                    
                        echo "<img src=\"icons/unknown.gif\" border=\"0\" /> ";                
                    }    
                    print '<a href=?arquivo='.$file.'>'.$file.'</a></td>';        
                    print '<td>';        if(!is_file($file)){        if($tamanho < "1024"){      
                    echo number_format($tamanho, 0, ",", ".")." byte(s)<br>";        
                }elseif($tamanho/1024 < "1024"){      
                    echo number_format($tamanho/1024, 2, ",", ".")." KB<br>";        
                }else{      
                    echo number_format($tamanho/(1024*1024), 2, ",", ".")." MB<br>";      
                    print '</td></tr>';         
                }    
            }else{        
                if($tam < "1024"){      
                    echo number_format($tam, 0, ",", ".")." byte(s)<br>";        
                }elseif($tamanho/1024 < "1024"){      
                    echo number_format($tam/1024, 2, ",", ".")." KB<br>";        
                }else{      
                    echo number_format($tam/(1024*1024), 2, ",", ".")." MB<br>";        
                }        
                print '</td></tr>';    
            }             
        }  
    }    
    print '<tr><td>';    
}    
print'</td></tr></table>';    
closedir($abre);
}
if($arquivo){     
    $tam = @ceil(@filesize($arquivo) / 1024);    
    $tamanho = @ceil(@filesize($dir."/".$arquivo) / 1024);    
    print '<br><br><b>Arquivo:</b> '.$arquivo;    
    print '<br><b>Tamanho:</b> ';    
    if(is_file($arquivo)){  
        print $tam;    
    }else{  
        print $tamanho;    
    }    
    print ' KB<br><br>';    
    $quebra = explode('.', $arquivo);    
    $ext = strtolower(end($quebra));    
    if(file_exists($arquivo) || file_exists($dir."/".$arquivo)){  
        if($ext=="jpg" || $ext=="gif" || $ext=="png" || $ext=="bmp"){      
            if($dir){    
                print '<img src='.$dir.'/'.$arquivo.'>';      
            }else{    
                print '<img src='.$arquivo.'>';      
            }  
        }else{      
            if($dir){    
                include $dir."/".$arquivo;       
            }else{    
                include $arquivo;      
            }  
        }        
    }else{   
        print '<script>alert("Arquivo não encontrado");</script>';    
    }  
    print '<br><br><a href=java script:history.back(1)>Voltar</a>';
}
?>

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...