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
-Gość-
post
Post #2





Goście







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

wyświetla:
Warning: opendir(path) [function.opendir]: failed to open dir: Invalid argument in D:\Program Files\WebServ\httpd\portal\newsy.php on line 7

Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in D:\Program Files\WebServ\httpd\portal\newsy.php on line 38

Warning: Invalid argument supplied for foreach() in D:\Program Files\WebServ\httpd\portal\newsy.php on line 48
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 - 16:29