Obsah fóra
PravidláRegistrovaťPrihlásenie




Odpovedať na tému [ Príspevkov: 4 ] 
AutorSpráva
Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 04.02.11
Prihlásený: 04.02.11
Príspevky: 2
Témy: 1
Príspevok NapísalOffline : 05.02.2011 11:27

Zdravím,

tento kód funguje tak, že sa nachádza v adresári so súbormi a do tabuľky vypisuje súbory, ktoré sa v ňom nachádzajú.
A ja chcem, aby mi v tej tabuľke zoraďoval výpis podľa abecedy. Keď napr. pridám neskôr nejaký súbor do adresára, aby sa v tabuľke zaradil podľa abecedy.

Ďík za pomoc


Kód:
<?php



   $standalone      = "true";

   

   $custom_script_name   = "subory.php";



   $enable_stats      = "true";



   $download_stats_file   = "./download_stats";



   $download_folder   = "./";



   $auto_create_filelist   = "true";



   // define download filelist when auto_create_filelist is set to "false"------------------------------------------------------------



   $download_filelist    = array(   "name1" => array(   "file1.zip",

                           "application/octet-stream",

                           "description1"),

                  "name2" => array(   "subfolder1/file2.zip",

                           "application/octet-stream",

                           "description2"),

                  "name3" => array(   "subfolder2/file1.zip",

                           "application/octet-stream",

                           "description3"));



   // standalone modus configuration-----------------------------------------------------------------------------------------------------------

   

   $headline_string   = "Súbory";



   $css_code      = <<<CSS_CODE

   

               /* here you can edit the css code */

   

               body   {   font-family:      Tahoma, sans-serif;   }

               img    {    border:         0px;

                     margin-top:      6px;         }

               h2   {   margin-bottom:      30px;

                     background-color:   #eeeeee;

                     color:         #c0c0c0;

                     letter-spacing:      .2em;

                     padding:      .2em;

                     text-align:      center;

                     border-top:      solid #aaaaaa 1px;

                     border-bottom:      solid #aaaaaa 1px;   }

                     

table{ width: 600px; margin: 10px auto; border-spacing: 0px; border-collapse: collapse; font-size:8pt;}

table th, table td{  padding: 5px; border: 1px solid #dcdcdc; }

table th{ text-align: center; background-color: #fefffe; background: url('hmrightbg.gif') repeat-x; }

                     

               th   {   background-color:   #dddddd;   }

               td   {   padding:      8px 10px 8px 10px;

                     background-color:   #ffffff;

                     border:         solid #dddddd 1px;   }



a { color: #000; background-color: inherit; font-weight: bold; text-decoration: none;}

a:hover { color: #aecc68; text-decoration: underline; }

   

               /* css code editing ends here */



CSS_CODE;

// !!! dont't change the position of the operator CSS_CODE and don't write anything behind, it must be alone at the beginning of the line



//################################################################################

//###                           ####

//###   CONFIGURATION - ends here                  ####

//###                           ####

//###   !!! don't edit anything above, except you know what you are doing !!!      ####

//###                           ####

//################################################################################



   $download   = $_GET["download"];

   $SCRIPT_NAME   = getenv("SCRIPT_NAME");



   // auto create download filelist-------------------------------------------------------------------------------------------------------------



   if ($auto_create_filelist=="true") {

      unset($download_filelist);

      $current_dir=getcwd();

      chdir($download_folder);

      $directory=dir("./");

      while ($file = $directory->read()) {

         if (is_file($file) and $file!=basename($SCRIPT_NAME) and $file!=basename($download_stats_file) and $file!=$custom_script_name) {

            $download_filelist[$file][0]=$file;

            $download_filelist[$file][1]="application/octet-stream";

         }

      }

      $directory->close();

      chdir($current_dir);

   }



   // download handling--------------------------------------------------------------------------------------------------------------------------



   if (isset($download)) {

      if (isset($download_filelist[$download])) {

         $filename=$download_folder.$download_filelist[$download][0];

         if (file_exists($filename)) {

            if ($enable_stats=="true") {

               if (file_exists($download_stats_file) and is_writable($download_stats_file)) {

                  foreach (file($download_stats_file) as $line) {

                     $array=explode("|",$line);

                     $download_stats_file_array[$array[0]]=$array[1];

                  }

                  $download_stats_file_array[$download]++;

                  $handle=fopen($download_stats_file,"w");

                  foreach ($download_stats_file_array as $value) {

                     fputs($handle,key($download_stats_file_array)."|".$value."|\n");

                     next($download_stats_file_array);

                  }

                  fclose($handle);

               }

               else { die("Sorry, no downloads avalible."); }

            }

            header("Content-Type: ".$download_filelist[$download][1]);

            header("Content-Disposition: attachment; filename=\"".basename($filename)."\"");

            readfile($filename);

            exit;

         }

         else { die("Sorry, but the requested file could not be found."); }

      }

      else { die("Sorry, but the requested download does not exist."); }

   }



   // initialize global variables-----------------------------------------------------------------------------------------------------------------



   $GLOBALS["SCRIPT_NAME"]         = getenv("SCRIPT_NAME");

   $GLOBALS["enable_stats"]      = $enable_stats;

   $GLOBALS["download_stats_file"]      = $download_stats_file;

   $GLOBALS["download_folder"]      = $download_folder;

   $GLOBALS["auto_create_filelist"]   = $auto_create_filelist;

   $GLOBALS["download_filelist"]      = $download_filelist;



   // functions------------------------------------------------------------------------------------------------------------------------------------------



   function manage_download_stats()

   {

      $download_stats_file   = $GLOBALS["download_stats_file"];

      $download_filelist   = $GLOBALS["download_filelist"];

      

      // create download stats file if missing-------------------------------------------------

      if (!file_exists($download_stats_file)) {

         $handle=fopen($download_stats_file,"w");

         foreach($download_filelist as $array) {

            fputs($handle,key($download_filelist)."|0|\n");

            next($download_filelist);

         }

         fclose($handle);

      }

      // read download stats file-------------------------------------------------------------------

      foreach (file($download_stats_file) as $line) {

         $array=explode("|",$line);

         $download_stats_file_array[$array[0]]=$array[1];

      }

      

      return $download_stats_file_array;

   }



   function print_download_table()

   {

      $enable_stats      = $GLOBALS["enable_stats"];

      $download_folder   = $GLOBALS["download_folder"];

      $auto_create_filelist   = $GLOBALS["auto_create_filelist"];

      $download_filelist   = $GLOBALS["download_filelist"];

      $SCRIPT_NAME      = $GLOBALS["SCRIPT_NAME"];

      

      // get download stats----------------------------------------------------------------------------   

      if ($enable_stats=="true") { $download_stats_file_array=manage_download_stats(); }

      // create download table from download file list------------------------------------

      echo "<table><tr><th>Súbory v adresári </th>";

      if ($auto_create_filelist!="true") { echo "<th>description</th>"; }

      echo "<th>Velkost</th>";

      if ($enable_stats=="true") { echo "<th>Zobrazení</th>"; }

      echo "</tr>";

      foreach($download_filelist as $download_filelist_array) {

         if (!isset($download_stats_file_array[key($download_filelist)])) { $download_stats_file_array[key($download_filelist)]=0; };

         echo "<tr><td><a href =\"$SCRIPT_NAME?download=".urlencode(key($download_filelist))."\" title=\"Klikni pre zobrazenie\">".key($download_filelist)."</a></td>";

         if ($auto_create_filelist!="true") { echo "<td>$download_filelist_array[2]</td>"; }

         echo "<td>".sprintf("%.1f",@filesize($download_folder.$download_filelist_array[0])/1024)."K</td>";

         if ($enable_stats=="true") { echo "<td>".$download_stats_file_array[key($download_filelist)]."</td>"; }

         echo "</tr>";

         next($download_filelist);

      }

      echo "</table>";

   }   



   // standalone output------------------------------------------------------------------------------------------------------------------------------



   if ($standalone=="true") {

      // header--------------------------------------------------------------------------------------------------------------------------------------------------

      echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">";

      echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" >";

      echo "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";

      echo "<meta name=\"author\" content=\"Till Biedermann\" />";

      echo "<meta name=\"description\" content=\"download system\" />";

      echo "<title>File download powered by TBmnet.de</title>";

      echo "<style type=\"text/css\">".$css_code."</style></head><body>";

      // body-----------------------------------------------------------------------------------------------------------------------------------------------------

      echo "<h2>".$headline_string."</h2>";

      print_download_table();

   }

?>


Offline

Užívateľ
Užívateľ
Zoradenie výpisu podľa abecedy

Registrovaný: 26.12.06
Prihlásený: 16.11.19
Príspevky: 3971
Témy: 181
Bydlisko: Nitra / Bra...
Príspevok NapísalOffline : 05.02.2011 11:34

http://sk.php.net/manual/en/function.sort.php

pozri si funkciu sort()







_________________
Sorry za prelkepy
Offline

Užívateľ
Užívateľ
Obrázok užívateľa

Registrovaný: 04.02.11
Prihlásený: 04.02.11
Príspevky: 2
Témy: 1
Príspevok Napísal autor témyOffline : 05.02.2011 11:39

emer píše:


Až tak moc sa do php nevyznám. Kam by som to mal asi zakomponovať do toho môjho kódu?


Offline

Užívateľ
Užívateľ
Zoradenie výpisu podľa abecedy

Registrovaný: 01.04.10
Prihlásený: 08.10.11
Príspevky: 339
Témy: 0
Príspevok NapísalOffline : 05.02.2011 12:18

if if if if if ... krasa


Odpovedať na tému [ Príspevkov: 4 ] 


Podobné témy

 Témy  Odpovede  Zobrazenia  Posledný príspevok 
V tomto fóre nie sú ďalšie neprečítané témy. Zoradenie podla abecedy

v Databázy

2

545

19.01.2012 16:41

zaciatocnik Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. zoradenie podla abecedy

v PHP, ASP

12

1461

25.08.2008 22:17

tomxi Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. zoradenie podla abecedy

v Databázy

5

1506

06.09.2008 18:38

rooobertek Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. LibreOffice - Zoradenie podla abecedy v calc

v Ostatné programy

0

1537

21.03.2012 16:01

scd Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Zoradenie výpisu

v PHP, ASP

3

454

23.11.2011 23:32

walther Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. zoradenie podla oblubenosi

v Databázy

4

681

16.06.2009 23:06

Snacker Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Zoradenie podla datumu

v PHP, ASP

29

1227

24.11.2007 18:19

Flety Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. zoradenie podla icq

v Redakčné systémy

5

508

30.03.2007 7:17

altt Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. zoradenie podla nazvu

v Databázy

2

369

18.02.2013 20:51

neopagan Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Nespravne zoradenie podla cisel

v Databázy

7

783

30.09.2010 20:29

camo Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Pascal - Zoradenie 5 čísel podľa veľksti

v Assembler, C, C++, Pascal, Java

8

1864

12.03.2010 21:48

juho Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Excel - zoradenie riadkov podľa kritérií v stlpcoch

v Ostatné programy

1

1263

14.04.2014 14:04

Slayer Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. WIN7-usporiadanie podla typu a zaroven podla datumu

v Operačné systémy Microsoft

1

722

10.10.2011 17:16

Logik Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Upravenie vypisu pola ..

v PHP, ASP

3

446

01.07.2009 17:05

stenley Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. Položky Start/Programy_ne podle abecedy

v Operačné systémy Microsoft

0

395

20.10.2006 21:29

bluenite Zobrazenie posledných príspevkov

V tomto fóre nie sú ďalšie neprečítané témy. optimalizacia vypisu z dtb

v PHP, ASP

12

661

21.09.2009 23:08

kmsa Zobrazenie posledných príspevkov


Nemôžete zakladať nové témy v tomto fóre
Nemôžete odpovedať na témy v tomto fóre
Nemôžete upravovať svoje príspevky v tomto fóre
Nemôžete mazať svoje príspevky v tomto fóre

Skočiť na:  

Powered by phpBB Jarvis © 2005 - 2024 PCforum, webhosting by WebSupport, secured by GeoTrust, edited by JanoF
Ako väčšina webových stránok aj my používame cookies. Zotrvaním na webovej stránke súhlasíte, že ich môžeme používať.
Všeobecné podmienky, spracovanie osobných údajov a pravidlá fóra