note 38701 added to function.sort
| From: | caco at farrapo dot com dot br | Date: | Sat, 03 Jan 2004 18:03:05 +0000 |
| Subject: | note 38701 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62874@lists.php.net to get a copy of this message | ||
Well, this page was generous with me, then i want retribuite with anything for anyone.
This is my code for list all files not begining with ".", and sort it by name, size, date
normal or reverse.
Is a ready-to-use, i think
in portuguese: esse é um código pronto pra uso, que lista os arquivos de um diretório, permitindo
ordenar por nome, tamanho, dia crescente ou decrescente.
<?php
if ($del) {
chmod($del, 0775);
unlink("$del");
header('Location: $PHP_SELF');
}
?>
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html;
charset=iso-8859-1">
<TITLE>Lista de Arquivos</TITLE>
<META HTTP-EQUIV="Content-Language" CONTENT="pt-br">
<style type="text/css">
<!--
td,input {font-family:verdana,arial,helvetica; font-size:12px;}
td {font-family:verdana,arial,helvetica; font-size:14px;}
.botao {color:#000000; background:#ffcc99}
.page { margin-top: 0cm; margin-bottom: 1.2cm }
A:link { font-family: Verdana; font-size:12px; text-decoration: none}
A:visited { font-family: Verdana; font-size:12px; text-decoration: none}
A:hover { font-family: Verdana; font-size:12px; text-decoration: none}
-->
</STYLE>
</HEAD>
<BODY class="page" BGCOLOR="#ffffcc" style="font-family: Verdana;
font-size: 10 pt; color: #CC6600">
<?php
echo<<<emHTML
<br><img src=http://www.farrapo.com.br/farrapob.gif>
Lista de arquivos nesse diretorio
<hr>
<table>
<tr>
<td width=250><b> arquivo <a
href="$PHP_SELF?ordem=a-">v</a> <a
href="$PHP_SELF?ordem=a+">^</a></td>
<td><b>bytes <a href="$PHP_SELF?ordem=s-">v</a> <a
href="$PHP_SELF?ordem=s+">^</a></td>
<td><b> data <a href="$PHP_SELF?ordem=d-">v</a>
<a href="$PHP_SELF?ordem=d+">^</a></td>
</tr>
emHTML;
$dirname=".";
$files = array();
$dir = opendir( $dirname );
while( $file = readdir( $dir ) ) {
if (!ereg("^\.",$file)) {
$files[] = $file;
switch ($ordem[0]) {
case "d": // by date
$filet[$file] = filemtime($file);
break;
case "s": // by size
$filet[$file] = filesize("$file");
break;
// case "n" // by name default
default:
$filet[$file] = $file;
break;
}
}
}
switch ($ordem[1]) {
case "-": //reverso
arsort($filet);
break;
default: //ascendente
asort($filet);
break;
}
while (list($file, $img) = each ($filet)) {
$sizearq = filesize("$file");
$totsize += $sizearq;
$contf += 1;
$modif = date ("Y-m-d H:i:s", filemtime($file));
echo <<<ATEK
<tr>
<td> <a href=$file>$file</a></td>
<td align=right>$sizearq</td>
<td> $modif</td>
<!-- td> <a href=$PHP_SELF?del=$file>Delete file</a></td -->
</tr>
ATEK;
}
echo <<<ATEK
<tr>
<td> Total $contf arquivos</td>
<td align=right>$totsize</td>
<td> </td>
</tr>
</table>
<br>
ATEK;
?>
----
Manual Page -- http://www.php.net/manual/en/function.sort.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38701
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38701&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38701&report=yes
Search -- http://master.php.net/manage/user-notes.php