Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Odczyt plików z katalogu jako obrazki
pjamorski
post
Post #1





Grupa: Zarejestrowani
Postów: 112
Pomógł: 0
Dołączył: 16.01.2008

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


Witam,



Kod
$licz=0;
 if ($handle = opendir('foty/'))
 {
        echo "Directory handle: $handle\n";
        echo "Files:\n";

        /* This is the correct way to loop over the directory. */
        while (($file = readdir($handle))!=false)
        {
         $licz++;
            //echo "$file\n";
            echo"<img src='+$file+'/>";
        }
    }
    echo $licz;
    closedir($handle);




Dlaczego nie wyświetla mi obrazków z podanego katalogu?


--------------------


Chęci to nie wszystko, trzeba działać.
B. Lee

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
athei
post
Post #2





Grupa: Zarejestrowani
Postów: 389
Pomógł: 141
Dołączył: 11.04.2009

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


Po jakiemu to jest ?
Kod
echo"<img src='+$file+'/>";

Jak już to
Kod
echo'<img src="foty/'.$file.'" />';
Go to the top of the page
+Quote Post
Pawel_W
post
Post #3





Grupa: Zarejestrowani
Postów: 1 675
Pomógł: 286
Dołączył: 15.06.2009
Skąd: Wieliczka

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


  1. <?php
  2. while (($file = readdir($handle))!=false)
  3.        {
  4.         $licz++;
  5.            //echo "$file\n";
  6.            echo"<img src='+$file+'/>";
  7.        }
  8. ?>

zamień na
  1. <?php
  2. while (($file = readdir($handle))!=false)
  3.        {
  4. if($file != "." && $file != "..")
  5. {
  6.         $licz++;
  7.            //echo "$file\n";
  8.            echo '<img src="foty/'.$file.'"/>';
  9. }
  10.        }
  11. ?>
Go to the top of the page
+Quote Post
-Wieviór-
post
Post #4





Goście







Ja mam taką funkcję do listowania plików:

  1. <?php
  2. function listDir($directory)
  3.        {
  4.        $skip = Array('.', '..', 'Thumbs.db');
  5.        if (is_dir($directory))
  6.            {
  7.            $images = array();
  8.            if ($handle = opendir($directory))
  9.                {
  10.                while ($file = readdir($handle))
  11.                    {
  12.                    if (!in_array($file, $skip))
  13.                        {
  14.                        $images[] = $file;
  15.                        }
  16.                    }
  17.                }
  18.            natsort($images);
  19.            }
  20.        return $images;
  21.        }
  22. ?>


A potem to zwykły foreach, dostajesz z funkci tablicę z wartościami zdjecie1.jpg, zdjecie2.jpg.
Go to the top of the page
+Quote Post

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 Aktualny czas: 19.08.2025 - 05:32