Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Jak w listowaniu ukryć plik .php
thejerremi
post 11.06.2016, 17:21:02
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 31.08.2015

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


Mam ustawione listowanie w taki sposób:
Kod
<?php
// ustawienie kontroli błędów
// pominę ten blok w kolejnych przykładach
error_reporting(E_ALL);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');

try {
    $directoryIterator = new DirectoryIterator(__DIR__);
    foreach ($directoryIterator as $dir) {kr
        if (!$dir->isDot()) {
            echo ' ' . $dir->getFilename() . '<br>';
        }
    }
} catch (Exception $e) {
    echo $e->getMessage();
}
?>


z tym kodem mam coś takiego:
Wiem, że isDot usuwa tą jedną kropkę i te 2 kropki, ale jak usunąć to index.php, żeby tylko widoczne były foldery?

Z góry dziękuję za pomoc
Go to the top of the page
+Quote Post
Pyton_000
post 11.06.2016, 17:23:59
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


http://php.net/manual/en/directoryiterator.getextension.php
Go to the top of the page
+Quote Post
thejerremi
post 11.06.2016, 17:28:07
Post #3





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 31.08.2015

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


Nie chodziło mi o pokazywanie rozszerzeń, tylko o to by w listowaniu pokazane były tylko pliki .zip
Go to the top of the page
+Quote Post
markuz
post 11.06.2016, 17:30:39
Post #4





Grupa: Zarejestrowani
Postów: 1 240
Pomógł: 278
Dołączył: 11.03.2008

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


if (!$dir->isDot()) - bo nie chcesz pokazywać katalogów, tak?
A więc podany przez @Pyton_000 $dir->getExtension() przyda Ci się, jak chcesz pokazywać tylko pliki .zip


--------------------
Go to the top of the page
+Quote Post
thejerremi
post 11.06.2016, 17:36:05
Post #5





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 31.08.2015

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




A jakoś dokładniej jak to zrobić, proszę tongue.gif ?

Ten post edytował thejerremi 11.06.2016, 17:39:25
Go to the top of the page
+Quote Post
com
post 11.06.2016, 17:37:37
Post #6





Grupa: Zarejestrowani
Postów: 3 032
Pomógł: 366
Dołączył: 24.05.2012

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


warunek i sprawdzić?
Go to the top of the page
+Quote Post
thejerremi
post 11.06.2016, 17:46:12
Post #7





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 31.08.2015

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


to powinno wyglądać tak:
Kod
        if (!$dir->isDot()) {
            echo ' ' . $dir->getExtension() . '<br>';


Czy jakoś inaczej?
Go to the top of the page
+Quote Post
com
post 11.06.2016, 17:51:53
Post #8





Grupa: Zarejestrowani
Postów: 3 032
Pomógł: 366
Dołączył: 24.05.2012

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


ah nie, warunek to if smile.gif

  1. if ($fileinfo->isFile() && $fileinfo->getExtension() !== 'php' ) {
  2. // tu rób co masz robić
  3. }


Ten post edytował com 11.06.2016, 17:54:10
Go to the top of the page
+Quote Post
LowiczakPL
post 11.06.2016, 18:43:44
Post #9





Grupa: Zarejestrowani
Postów: 531
Pomógł: 55
Dołączył: 3.01.2016
Skąd: Łowicz

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


  1.  
  2. <?php
  3.  
  4. ini_set('display_errors', 'on');
  5. ini_set('display_startup_errors', 'on');
  6.  
  7. try {
  8. $directoryIterator = new DirectoryIterator(__DIR__);
  9. foreach ($directoryIterator as $dir) {
  10. if (!$dir->isDot()) {
  11. $rozszerzenie = pathinfo($dir->getFilename(), PATHINFO_EXTENSION);
  12. if ($rozszerzenie!='php') {
  13. echo ' ' . $dir->getFilename() . '<br>';
  14. }
  15. }
  16. }
  17. } catch (Exception $e) {
  18. echo $e->getMessage();
  19. }
  20.  


Ten post edytował LowiczakPL 11.06.2016, 18:48:55


--------------------
Szukam zleceń Symfony, Laravel, Back-End, Front-End, PHP, MySQL ...
Go to the top of the page
+Quote Post
com
post 11.06.2016, 18:56:02
Post #10





Grupa: Zarejestrowani
Postów: 3 032
Pomógł: 366
Dołączył: 24.05.2012

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


@up ale to raczej jak php nie wspiera, a od 5.3 wspiera smile.gif

i !==, zawsze lepiej stosować tak samo jak === wink.gif
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: 19.04.2024 - 07:32