0

I would like to know how to show a small message when I use the Scandir function to show files of a folder,in place of a link if this folder is empty...

I show you the code :

<div class="div1">
                        <h3>Vos Factures :</h3>
                        <?php
                        
                        $login = "";
                        
                        if(isset($_POST['login'])){
                            $login = $_SESSION['login'];
                            
                        }
                        "SELECT password FROM utilisateurs WHERE login =:login";
                        
                        $file= scandir('membres/' . $_SESSION['login'] . '/factures/');
                        
                        
                        foreach($file as $file) {
                            
                        ?>
                        
                        
                        <li class="pdf"><a  href="membres/<?php  if ( $file != '.' && $file != '..' && $file != 'index.php') { echo $_SESSION['login'] . '/factures/'.$file  ?>"><?php  if ($file != '.' && $file != '..' && $file != 'index.php') { echo    $file ; }?></a></li>
                        <?php
                        }
                        }
                        ?>
                    </div>

So I would like to replace the link by a small message or and other thing if there is no file in folder.

Many thanks for your help.

Cordially

Emrys
  • 1
  • 1

1 Answers1

0

SOLVED :

Sorry @calmelsWriteInCalmelCase,

I didn't have closed the code, so I did :

<?php
                        
                        $login = "";
                        
                        if(isset($_POST['login'])){
                            $login = $_SESSION['login'];
                            
                        }
                        "SELECT password FROM utilisateurs WHERE login =:login";
                        
                        $file= scandir('membres/' . $_SESSION['login'] . '/factures/');
                        
                        $items_count = count($file);
                        if ($items_count <= 2)
                        {
                            $empty = true;
                            echo "Aucun fichier ici";
                        }
                        else {
                            
                       
                        foreach($file as $file) {
                            
                        ?>
                        
                        
                        <li class="pdf"><a  href="membres/<?php  if ( $file != '.' && $file != '..' && $file != 'index.php') { echo $_SESSION['login'] . '/factures/'.$file  ?>"><?php  if ($file != '.' && $file != '..' && $file != 'index.php') { echo    $file ; }?></a></li>
                        <?php
                        }
                        }
                        }
                        ?>

And it Works great,

I don't know if this is the right thing to do, but it's good for me.

Many thanks for your held.

Cordially,

Emrys

Emrys
  • 1
  • 1