Stránka 1 z 1

system pro index souboru

Napsal: 31 srp 2009 16:08
od simPod
nemate nekdo nejaky system pro index souboru - kdybych pak zobrazil napr http://mojedomena.cz/files/ tak se mi objevi prehledny seznam souboru a vedle kazdeho by byl odkaz na download a vedle odkazu napsana velikost? nechci klasicky index souboru, chtel bych neco uzivatelsky privetiveho

Re: system pro index souboru  Vyřešeno

Napsal: 31 srp 2009 19:17
od mike007
Mám a používám toto:

vypis.php:

Kód: Vybrat vše

<?php
////////////////////////////////////
$file = $_POST['file'];
if (isset ($file)) {
   dnld ($file);
   exit;
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1250' />
<meta name="author" content="Michael Ruprecht">
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Pragma" content="no-cache">
<title>Uploader bastleni.eu</title>

<style type="text/css">
<!--
body {background-color:ghostwhite; font:normal 80% Arial, Helvetica, Sans-Serif; color:navy;}
h1 {font:bold 130% Arial, Helvetica, Sans-Serif; color:firebrick;}
h2 {font:bold 120% Arial, Helvetica, Sans-Serif;}
table {border-width:0px; border-collapse:collapse;}
th {border-width:1px 0px 1px 0px; border-color:silver; border-style:solid; padding:0px 3px;}
td {border-width:1px 0px 0px 0px; border-color:silver; border-style:dotted; padding:0px 3px;}
form {margin:0px; padding:0px;}
.submit {cursor:hand; background-color:transparent; border-width:0px; text-decoration:underline; color:purple;}
-->
</style>

</head>
<body>

<?php
$dir = @opendir ('./');
echo "<h1>Soubory ulo·ené v uploaderu : </h1>";

////////////////////////// navigace
echo "<h2>";
$self = $_SERVER['PHP_SELF'];
$pole = explode("/", $self);
array_pop ($pole);   // remove script name
array_shift ($pole); // remove leading slash

$host = $_SERVER["SERVER_NAME"];
$host = "http://" . $host . "/";
echo "<a href=$host>domů</a> ";
while (list (, $hodnota) = each ($pole)) {
   $cesta .= "$hodnota" . "/";
//   $odkaz = "&gt;&gt;&gt;&nbsp;<a href=\"$host$cesta" . "index.php\">$hodnota</a>&nbsp;";
   $odkaz = "&gt;&gt;&gt;&nbsp;<a href=\"$host$cesta\">$hodnota</a>&nbsp;";
   echo "$odkaz";
}
echo "</h2>";


///////////////////////// tabulka
echo "<table cellspacing='0'>";
echo "<tr><th>Číslo</th><th>Typ</th><th>Soubor</th><th>Bajtů</th><th>Aktualizace</th><th>Otevřít</th></tr>";
if (dir == false) exit ('Nelze otevřít slo·ku.');
$arr = array ();
while (($file = readdir ($dir)) !== false) {
   $ext = strrev ($file);
   $pos = strpos ($ext, ".");
   if ($pos === false) {
      $ext = '';
   }
   else {
      $ext = substr ($ext, 0, $pos);
      $ext = strrev ($ext);
   }
   if (substr ($file, 0 ,1) != '.' && $file != 'index.php') {
      $fileSize = filesize ($file);
      $fileDate = date ("d/m/y H:i:s", filemtime($file));
      $isDir = filetype ($file);
      if ($isDir == 'dir') {
         $isDir = "&nbsp;Slo·ka&nbsp;";
//         $file .= '/'; //// ????
         $ext = 'dir';
      }
      else
         $isDir = "&nbsp;Soubor&nbsp;";
      $a = $isDir . 'Ź' . $file . 'Ź' . $fileSize . 'Ź' . $fileDate . 'Ź' . $ext;
      $arr [] = $a;
   }
}
natcasesort ($arr);
reset ($arr);
$klic = 0;
while (list (, $hodnota) = each ($arr)) {
   list ($isDir, $file, $fileSize, $fileDate, $ext) = explode ('Ź', $hodnota);
   echo "<tr>";
   $klic++;

   echo "<td align=right>$klic</td>";
   echo "<td>$isDir</td>";
   echo" <td><b>$file</b></td>";
   echo "<td align=right>$fileSize</td>";
   echo "<td><b>$fileDate</b></td>";
   echo "<td align=center>";
   $file = rawurlencode($file); //// ????
   if($ext == 'dir') $file .= '/'; //// ????

   if (eregi ("^dir|rar|zip$", $ext)) {
      echo "<a href=\"$file\" . \"index.php\">$ext</a>";
   }
   else {
      echo "
      <form method=post action=\"$self\">
      <input type=hidden value=\"$file\" name=file>
      <input type=submit value=\"$ext\" class=submit>
      </form>";
   }

   echo "</td>";
   echo "</tr>";
}
echo "</table>";
echo "<p>Celkem souborů: " . count ($arr);

closedir ($dir);
?>
</body>
</html>
<?php
exit;

////////////////////////////// download
function dnld ($file) {
   header ("Content-Type: application/octet-stream");
   header ("Content-Length: ".filesize($file));
   header ("Content-Disposition: attachment; filename=$file");
   readfile ($file);
} // end func

?>


Hlavičku si uprav podle sebe. Soubor vypis.php stačí uložit do složky se soubory a zavolat ho. Vypíše pořadové číslo, typ souboru, název, velikost, čas uploadování, a příponu souboru (po kliknutí na ni dojde k downloadu)

Re: system pro index souboru

Napsal: 31 srp 2009 19:28
od simPod
to vypada velmi pekne
dekuji mnoho