Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]nazwy bez spacji
tomek34
post 1.05.2009, 17:10:56
Post #1





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 28.04.2009

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


Witam!
Jak mogę wyświetlić zawartość foldelu z pominięciem plików ze spacjami w nazwie?
Plik któy wyświetla mi obecnie zawartość wygląda następująco:

  1. <?php
  2.                  $dir = "D:sermoidane";
  3.                  function printDir($dir)
  4.                  {
  5.                    $fd = opendir($dir);
  6.                      if(!$fd) return false;
  7.                        while (($file = readdir($fd)) !== false){
  8.                      if($file != "." && $file != ".."){
  9.                      echo("<a href=\"download.php?name=");
  10.                      echo("$file\" class='style3'>$file</a><br />");
  11.                      }
  12.                      }
  13.                      closedir($fd);
  14.                  }
  15.                  printDir($dir);
  16.             ?>



Pozdrawiam
Go to the top of the page
+Quote Post
outsider
post 1.05.2009, 17:19:28
Post #2





Grupa: Zarejestrowani
Postów: 267
Pomógł: 36
Dołączył: 8.08.2008

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


strpos
  1. <?php
  2. $pos = strpos($file, ' ');
  3. if($pos !== false) {
  4. print 'plik zawiera spacje :)';
  5. }
  6. ?>


Ten post edytował *OuTSideR* 1.05.2009, 17:29:30
Go to the top of the page
+Quote Post
tomek34
post 1.05.2009, 17:21:44
Post #3





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 28.04.2009

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


ale chodzi o to żeby te pliki nie zostały wogóle wyświetlone.
Go to the top of the page
+Quote Post
outsider
post 1.05.2009, 17:23:05
Post #4





Grupa: Zarejestrowani
Postów: 267
Pomógł: 36
Dołączył: 8.08.2008

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


  1. <?php
  2. $dir = "D:sermoidane";
  3.                 function printDir($dir)
  4.                 {
  5.                   $fd = opendir($dir);
  6.                     if(!$fd) return false;
  7.                       while (($file = readdir($fd)) !== false){
  8.                     $pos = strpos($file, ' ');
  9.                     if($file != "." && $file != ".." && $pos !== false){
  10.                     echo("<a href=\"download.php?name=");
  11.                     echo("$file\" class='style3'>$file</a><br />");
  12.                     }
  13.                     }
  14.                     closedir($fd);
  15.                 }
  16.                 printDir($dir);
  17. ?>


Ten post edytował *OuTSideR* 1.05.2009, 17:32:46
Go to the top of the page
+Quote Post
wNogachSpisz
post 1.05.2009, 17:23:28
Post #5





Grupa: Zarejestrowani
Postów: 1 233
Pomógł: 87
Dołączył: 6.03.2009

Ostrzeżenie: (40%)
XX---


  1. <?php
  2. function printDir($path) {
  3.    if ( ! is_dir($path))
  4.       return false;
  5.    foreach ( glob($path) as $item ) {
  6.       $item = basename($item);
  7.       if ( preg_match('# #', $item))
  8.          continue;
  9.       echo "<a href=\"download.php?name={$item}\" class=\"style3\">{$item}</a><br />\n";
  10.    }
  11. }
  12. ?>
Go to the top of the page
+Quote Post
outsider
post 1.05.2009, 17:32:31
Post #6





Grupa: Zarejestrowani
Postów: 267
Pomógł: 36
Dołączył: 8.08.2008

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


poprawiony, sorki smile.gif :

  1. <?php
  2. $dir = "D:sermoidane";
  3.                function printDir($dir)
  4.                {
  5.                  $fd = opendir($dir);
  6.                    if(!$fd) return false;
  7.                      while (($file = readdir($fd)) !== false){
  8.                    $pos = strpos($file, ' ');
  9.                    if($file != "." && $file != ".." && $pos === false){
  10.                    echo("<a href=\"download.php?name=");
  11.                    echo("$file\" class='style3'>$file</a><br />");
  12.                    }
  13.                    }
  14.                    closedir($fd);
  15.                }
  16.                printDir($dir);
  17. ?>

ale mozna uzyc funkcji urlencode, i pozniej urldecode i odczytac plik ze spacja smile.gif

Ten post edytował *OuTSideR* 1.05.2009, 17:35:09
Go to the top of the page
+Quote Post
tomek34
post 1.05.2009, 20:06:47
Post #7





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 28.04.2009

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


dzięki!
działa idealnie!
właśnie o to mi chodziło
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 Wersja Lo-Fi Aktualny czas: 13.08.2025 - 22:53