A basename
should only solve:
<?php
// Recupera a lista de todos os arquivos:
$itens = glob("arquivos/*");
// Ordena os arquivos pela data de modificacão:
usort($itens, function ($a, $b) {
return filemtime($a) < filemtime($b);
});
// Pega apenas os cinco últimos modificados:
$cont = array_slice($itens, 0, 5);
foreach ($cont as $arq) {
$nome = basename($arq);
echo '<a href="' . $arq . '"> '. $nome . '</a><br>';
}
Or (depends on what you want):
$nome = basename($arq);
echo '<a href="' . $nome . '"> '. $nome . '</a><br>';
If you want without the extension (if the files are all of the same format):
<?php
// Recupera a lista de todos os arquivos:
$itens = glob("arquivos/*");
// Ordena os arquivos pela data de modificacão:
usort($itens, function ($a, $b) {
return filemtime($a) < filemtime($b);
});
// Pega apenas os cinco últimos modificados:
$cont = array_slice($itens, 0, 5);
foreach ($cont as $arq) {
$nome = basename($arq, '.pptx');
echo '<a href="' . $arq . '"> '. $nome . '</a><br>';
}
If it has various extensions:
<?php
// Recupera a lista de todos os arquivos:
$itens = glob("arquivos/*");
// Ordena os arquivos pela data de modificacão:
usort($itens, function ($a, $b) {
return filemtime($a) < filemtime($b);
});
// Pega apenas os cinco últimos modificados:
$cont = array_slice($itens, 0, 5);
foreach ($cont as $arq) {
$nome = pathinfo($arq, PATHINFO_FILENAME);
echo '<a href="' . $arq . '"> '. $nome . '</a><br>';
}
Young man, where did you get this? The question talks about file system, not url. I denied your answer, because it doesn’t make sense here.
– Wallace Maxters
$_SERVER['REQUEST_URI']
returns the path of php running and hitchhiked. The rest of the stretchbasename()
and theif
is what settles the issue. Alias,basename()
is at the basis of the accepted answer. Next, I will be more explicit... Or maybe not.– Rene Freak
The problem is that it has nothing to do with what was asked
– Wallace Maxters