Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyświetlanie plików z folderu
-Gość_MICHALL_*-
post
Post #1





Goście







Czy jest jakiś skrtyp w php który wyświetlał by wszystkie pliki txt znajdujące się w podamym folderze??
i czy da się za jego pomocą stworzyć tabele w której wyświetlone były by te pliki wraz z zmiennymi w nich zamieszczonymi?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
NetJaro
post
Post #2





Grupa: Zarejestrowani
Postów: 475
Pomógł: 0
Dołączył: 1.04.2005
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Ludzie, po co na siłe (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) ?

Wystarczy przeczytać komentarze do funkcji readdir" title="Zobacz w manualu php" target="_manual.

  1. <?php
  2. function listImages($dirname, $sortby, $sortdir) {
  3.  
  4. $ext = array("jpg", "png", "jpeg", "gif");
  5. $files = array();
  6.  if($handle = opendir($dirname)) {
  7.  while(false !== ($file = readdir($handle))){
  8.  for($i=0;$i<sizeof($ext);$i++){
  9.  if(stristr($file, ".".$ext[$i])){ //NOT case sensitive: OK with JpeG, JPG, ecc.
  10.  $imgdata = getimagesize($dirname . "/" . $file);
  11.  $filesize = filesize($dirname . "/" . $file);
  12.  //Some formats may contain no image or may contain multiple images.
  13.  //In these cases, getimagesize() might not be able to properly determine the image size.
  14.  //getimagesize() will return zero for width and height in these cases.
  15.  if($imgdata[0] && $imgdata[1] && $filesize){
  16.  $files[] = array(
  17.  "name" => $file,
  18.  "width" => $imgdata[0],
  19.  "height" => $imgdata[1],
  20.  "size" => $filesize
  21.  );
  22.  } 
  23.  }
  24.  }
  25.  }
  26.  closedir($handle);
  27.  }
  28.  
  29.  //obtain an array of columns
  30.  foreach ($files as $key => $row) {
  31.  $name[$key] = $row['name'];
  32.  $width[$key] = $row['width'];
  33.  $height[$key] = $row['height'];
  34.  $size[$key] = $row['size'];
  35.  }
  36.  
  37. return array_multisort($$sortby, $sortdir, $files) ? $files : false;
  38. }
  39. //end listImages
  40.  
  41. //start test
  42. $sortby = "width"; // sort-by column; accepted values: name OR width OR height OR size
  43. $path = "path"; // path to folder
  44. $sortdir = SORT_ASC; // sorting order flags; accepted values: SORT_ASC or SORT_DESC
  45.  
  46. $files = listImages($path, $sortby, $sortdir);
  47. foreach ($files as $file){
  48.  echo 'name = <strong>' . $file['name'] . '</strong> width = <strong>' . $file['width'] . '</strong> height = <strong>' . $file['height'] . '</strong> size = <strong>' . $file['size'] . '</strong><br />';
  49. }
  50. //end test
  51. ?>

(IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 3.10.2025 - 20:52