Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Przeróbka skryptu, Na odwrót :)
-Słoń Edward-
post 13.06.2005, 17:28:23
Post #1





Goście







Hej! Znalazłem gdzieś w przykładach taki skrypcik. Chciałbym by ten oto skrypcik pokazywał pliki w odwrotnej kolejności. Wiem, że trzeba coś zrobić z tablicą, ale nie za bardzo się na tym znam...
Teraz, gdy mam pliki x2.php, x11.php, x5.php, x24.php, x9.php, x13.php, x10.php, wyświetla mi je w kolejności:

-x.php
-x.php
-x.php
-x.php
-x.php
-x.php
-x.php

A ja bym chciał, by wyświetlił je w takiej:

-x.php
-x.php
-x.php
-x.php
-x.php
-x.php
-x.php

Aoto kod:

  1. <?php
  2.  
  3.  # Do we have a path? if not, it's the current directory
  4.  $path = $_GET[&#092;"path\"];
  5.  if( !isset( $path ) || $path == &#092;"\" ) {
  6.  $path = &#092;".\";
  7.  }
  8.  
  9.  //# Print out for navigation
  10.  //print \"Current path: <b>\" . $path . \"</b><br />\";
  11.  
  12.  # Initialise list arrays, directories and files separately and array counters fo
  13.  them
  14.  $d_arr = array(); $d = 0;
  15.  $f_arr = array(); $f = 0;
  16.  
  17.  # Open possibly available directory
  18.  if( is_dir( $path ) ) {
  19.  if( $handle = opendir( $path ) ) {
  20.  while( false !== ( $file = readdir( $handle ) ) ) {
  21.  # Make sure we don't push parental directories or dotfiles (unix) into the arrays
  22.  if( $file != &#092;".\" && $file != \"..\" && $file[0] != \".\" ) {
  23.  if( is_dir( $path . &#092;"/\" . $file ) )
  24.  # Create array for directories
  25.  $d_arr[$d++] = $file;
  26.  else
  27.  # Create array for files
  28.  $f_arr[$f++] = $file;
  29.  }
  30.  }
  31.  }
  32.  }
  33.  
  34.  # Wrap things up if we're in a directory
  35.  if( is_dir( $handle ) ) closedir( $handle );
  36.  
  37.  # Sort and reset the arrays
  38.  asort( $d_arr ); reset( $d_arr );
  39.  asort( $f_arr ); reset( $f_arr );
  40.  
  41.  # Print a parent directory link
  42.  $d_prev = substr( $path, 0, ( strrpos( dirname( $path . &#092;"/.\" ), \"/\" ) ) );
  43.  print &#092;"<a href=\"?path=\" . $d_prev . \"\"> Spis kategorii </a><br />n\";
  44.  
  45.  # Print the directory list
  46.  for( $i=0; $i < count( $d_arr ); $i++ ) {
  47.  # Print with query string
  48.  print &#092;"<img border=/\"0/\" src=/\"../folder.gif/\" width=/\"16/\" height=/\"14/\"> <a href=\"?path=\" . $path . \"/\" . $d_arr[$i] . \"\">\" . $d_arr[$i] . \"</a>/<br />n\";
  49.  }
  50.  
  51.  # Print file list
  52.  for( $i=0; $i < count( $f_arr ); $i++ ) {
  53.  $nazwa = substr($f_arr[$i], 0, strpos($f_arr[$i], '.'));
  54.  # Only print path and filename
  55.  print &#092;"<img border=/\"0/\" src=/\"../img.gif/\" width=/\"14/\" height=/\"16/\"> <a href=\"\" . $path . \"/\" . $f_arr[$i] . \"\"> \" . $f_arr[$i] . \"</a>\";
  56.  # We may want a file size. NOTE: needs $path to stat
  57.  if( filesize( $path . &#092;"/\" . $f_arr[$i] ) >= 1024 ) {
  58.  # Size in kilobytes
  59.  print &#092;" \" . round( filesize( $path . \"/\" . $f_arr[$i] ) / 1024, 1 ) . \" KB<br />n\";
  60.  } elseif( filesize( $path . &#092;"/\" . $f_arr[$i] ) >= 1048576 ) {
  61.  # Size in megabytes
  62.  print &#092;" \" . round( filesize( $path . \"/\" . $f_arr[$i] ) / 1024 / 1024, 1 ) . \" MB<br />n\";
  63.  } else {
  64.  # Size in bytes
  65.  print &#092;" \" . filesize( $path . \"/\" . $f_arr[$i] ) . \" bytes<br />n\";
  66.  }
  67.  }
  68.  
  69. ?>


---

aleksander
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 13:08