0
Hello, I have a PHP code that works well for what was proposed, but I need some adjustments to it.
The code in question already lists the directories and the files, but in directories that I have files and subdirectories it lists me shuffled.
I would like the code to separate what is a file and what is a directory, showing the directories at the beginning of the list, and the acquisitions afterwards.
If possible after separation, also list alphabetically within your type.
Example of expected output:
Bee/
Rumours/
Koala/
abelhass.
png.
curd.png
My knowledge in PHP is practically null, but it was the best alternative I could find. If anyone can help me adapt the code, I’d really appreciate it;
<html lang="pt-br">
<head>
<title class="title h1"></title>
<meta http-equiv="Content-Language" content="pt-br" charset="ISO-8859-1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Fondamento|Hanuman|Kaushan+Script|Nanum+Pen+Script|Orbitron&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Comfortaa&display=swap" rel="stylesheet">
</head>
<style type="text/css">
.bg-grey{
background-color: #E6E6E6;
}
.bg-azulClarrisimo{
background-color: #E0F2F7;
}
.title{
font-family: 'Fondamento', cursive;
}
.comfortaa{
font-family: 'Comfortaa', cursive;
}
@media only screen and (max-width: 900px) {
.tamanho{
font-size: 10px;
}
}
</style>
<body>
<?php
//diretorio
$baseDir = './';
$abreDir = (array_key_exists('dir', $_GET) ? $_GET['dir'] : $baseDir);
$openDir = dir($abreDir);
$strrdir = strrpos(substr($abreDir,0,-1),'/');
$backDir = substr($abreDir,0,$strrdir+1);
if($abreDir != $baseDir){
echo '<a class="btn btn-warning " href="index.php?dir='.$backDir.'"><i class="fa fa-arrow-left"></i>Voltar</a>';
}
echo '<hr>';
echo '<table class="text-left table table-dark reponsive tamanho" width="100%" cellspacing="0" cellspadding="">';
while($arq = $openDir -> read()):
if($arq != '.' && $arq != '..' && $arq != 'index.php'):
if(is_dir($abreDir.$arq)){
//pastas
echo '<tr>';
echo '<td class="alert alert-info text-left tamanho"><a class="form-control btn text-left tamanho" href="index.php?dir='.$abreDir.$arq.'/"><i class="fa fa-bars"></i>   '.$arq.'</a></td>';
echo '</tr>';
}else{
//arquivos
echo '<tr>';
echo '<td class="alert text-right tamanho"><a class="form-control btn text-white text-right tamanho" href="'.$abreDir.$arq.'" target="_blank">'.$arq.'     <i class="fa fa-download" ></i></a></td>';
echo '</tr>';
}
endif;
endwhile;
echo '</table>';
echo '<hr>';
if($abreDir != $baseDir){
echo '<a class="btn btn-warning" href="index.php?dir='. $backDir.'"><i class="fa fa-arrow-left"></i>Voltar</a>';
}
?>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
I know it’s a lot to ask, but could you help me adapt your code to mine? My knowledge of PHP is null. Your code works well, but only works in the initial directory. One solution I found using your code was to put an index.php file in each directory and sub-directory. But it is very amateur and nothing practical and functional.
– Gustavo Henrique
takes a look that I edited the answer including something that should help.
– Marcos Vinicius