Afficher plusieurs page de résultats

Bonjour,
Je suis en train de créer un FTP public, sans mySQL juste en php, et j'aimerai que touts les 15 fichiers listées, une nouvelle page se créer. Possible de faire cela simplement ?
Voilà mon code:

<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Fareoh.fr - FTP</title>
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <link rel="stylesheet" href="http://fareoh.fr/assets/css/main2.css" />
  <link rel="icon" type="image/png" href="http://dev.fareoh.fr/img/favicon.png" />
 </head>
 <body id="top">
   <header id="header">
    <div class="content">
     <br /><br />
       <form>
   <table style="width:100%; border:2;font-size:10px;">
   <tr style=" border:solid, black;" >
    <th><b>Nom</b></th>
    <th><b>Taille</b></th> 
    <th><b>Upload</b></th>
    <th><b>Télécharger</b></th>
    <th><b>Action</b></th>
    <th><b>Type</b></th>
    </tr>
<?php
$nb_fichier = 0;
$root_dir='./ftp/';

function actionfichier($fichier) {
    $type = substr(strrchr($fichier, '.'), 1 );
    if ($type == 'osu' or $type == 'osz' or $type == 'rar' or $type == 'zip' ) {
         return 'Aucune';}
    if ($type == 'mp3' or $type == 'wav' or $type == 'm4a' or $type == 'wmv' or $type == 'aac') {
        return '<a href"http://ftp.fareoh.fr/player_audio.php?value='.$fichier.'">Ecouter</a' ;}
    if ($type == 'png' or $type ==  'PNG' or $type == 'jpg'  or $type == 'JPG' or $type ==  "gif" or $type ==  "GIF" or $type == 'tiff' or $type == 'TIFF' or $type == 'BPM'or $type == 'bmp') {
 return '<a href="http://ftp.fareoh.fr/visionneuse?value='.$fichier.'" rel="nofollow noopener noreferrer" target="_blank">Voir</a>' ;}
    if ($type !== 'osu' or $type !== 'osz' or $type !== 'MP3' or $type !== 'mp3' or $type !== 'MP4' or $type !== 'mp4' or $type !== 'wmv' or $type !== 'WMV' or $type !== 'acc' or $type !== 'bpm' or $type !== 'BMP' or $type !== 'tiff' or $type !== 'tiff'
     or $type !== 'gif' or $type !== 'm4a' or $type !== 'jpg' or $type !== 'JPG' or $type !== 'png' or $type !== 'PNG' ){
    return 'Aucune' ;}
 if ($type == 'txt' or $type == 'TXT'){
 return '<a href="http://ftp.fareoh.fr/txt.php?value='.$fichier.'" rel="nofollow noopener noreferrer" target="_blank">Lire</a>';}
} 

  function taille($fichier){
    $taille = filesize($fichier);
    if ($taille >= 1073741824){
    $taille = round($taille / 1073741824 * 100) / 100 . " Go";
     }elseif ($taille >= 1048576){
    $taille = round($taille / 1048576 * 100) / 100 . " Mo";
     }elseif ($taille >= 1024){
    $taille = round($taille / 1024 * 100) / 100 . " Ko";
     }elseif ($taille > 0){
    $taille = $taille . " o";
     }else{
    $taille="-";
       }
    return $taille;
}
  echo '<ul>';

if($dossier = opendir($root_dir)){
 while($fichier = readdir($dossier)){
  if($fichier != '.' && $fichier != '..' && $fichier != 'folder.php'){
   $nb_fichier++;
   echo     '<tr>
      <th> <a href="'. $root_dir.$fichier . '" rel="nofollow noopener noreferrer" target="_blank">'. $root_dir.$fichier . ' </th>
      <th>' . taille($root_dir.$fichier) . '</th>
      <th>'.date("d/m/20y", filectime($root_dir.$fichier)).' à '.date("H:i", filectime($root_dir.$fichier)).'</th>
      <th><a href="./ftp/' .$fichier . '" rel="nofollow noopener noreferrer" target="_blank" download="' . $fichier . '"><center><img src=""quot;"quot;download.png"></a></center></th>
      <th>'.actionfichier($fichier).'</th>
      <th>'.substr(strrchr($fichier, '.'), 1 ).'</th>
      </tr>';
    }
   }
 }
echo '</ul>';
$fichier_dir= ($root_dir.$fichier);
?>
    <th><a href="upname.php" rel="nofollow noopener noreferrer" target="_blank" style="font:14px;"><img src=""quot;"quot;upload.png" height="15px;" > Upload un nouveau fichier</a><i>  (sécurisé)</i></th> 

    </tr>
   </table>
<?php closedir($dossier); ?>
 </form>
  <div style=" vertical-align:top;" ></div> 
     </div>
   </header>
   <footer id="footer">
    <ul class="icons">
     <li><a href="https://twitter.com/FareohAsc" rel="nofollow noopener noreferrer" target="_blank" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
    </ul>
    <p class="copyright">© Fareoh.fr 2017 </p>
   </footer>
   <script src=""quot;"quot;http://fareoh.fr/assets/js/jquery.min.js"></script>
   <script src=""quot;"quot;http://fareoh.fr/assets/js/jquery.scrolly.min.js"></script>
   <script src=""quot;"quot;http://fareoh.fr/assets/js/skel.min.js"></script>
   <script src=""quot;"quot;http://fareoh.fr/assets/js/util.js"></script>
   <script src=""quot;"quot;http://fareoh.fr/assets/js/main.js"></script>

 </body>
</html>


5 réponses

  1. Contributeur Ambassadeur
    ta fonction n'est pas correcte, suggestion:
    function actionfichier($fichier) {
        $type = substr(strrchr($fichier, '.'), 1 );
        if ($type == 'mp3' or $type == 'wav' or $type == 'm4a' or $type == 'wmv' or $type == 'aac') {
            return '<a href"http://ftp.fareoh.fr/player_audio.php?value='.$fichier.'">Ecouter</a' ;}
        if ($type == 'png' or $type ==  'PNG' or $type == 'jpg'  or $type == 'JPG' or $type ==  "gif" or $type ==  "GIF" or $type == 'tiff' or $type == 'TIFF' or $type == 'BPM'or $type == 'bmp') {
     return '<a href="http://ftp.fareoh.fr/visionneuse?value='.$fichier.'" rel="nofollow noopener noreferrer" target="_blank">Voir</a>' ;}
     if ($type == 'txt' or $type == 'TXT'){
     return '<a href="http://ftp.fareoh.fr/txt.php?value='.$fichier.'" rel="nofollow noopener noreferrer" target="_blank">Lire</a>';}
        return 'Aucune' ;
    } 
    0
    1. Contributeur Ambassadeur
      je suppose que tu veux que ta page affiche les 15 premiers fichiers, puis envoie un lien, et que, quand l'utilisateur clique ce lien, la page affiche les 15 fichiers suivants. c'est bien cela?
      si oui, il faut faire ceci:
      1) ajouter un paramètre optionnel à la page, qui indique le numéro du premier fichier à afficher.
      2) si le paramètre est présent, et est un nombre positif, en tenir compte, et ne pas afficher les N premiers fichiers
      3) n'afficher que 15 fichiers
      4) si il reste des fichiers à afficher, envoyer un lien vers la page, avec N+15 en paramètre
      .
      As-tu besoin d'aide pour réaliser cela? Veux-tu proposer quelque-chose, une idée, un début de code?
      0
      1. je n'ai aucune idée de quoi proposer...
        :/
        0
      2. Contributeur Ambassadeur
        Je propose de commencer par ceci:
        1) ajoute le code suivant au début de ton code php:
        $passer = 0;
        if ( isset ($_GET['passer']) )
         if (intval($_GET['passer']) > 0)
          $passer=intval($_GET['passer']);

        2) remplace le while (lignes 71 à 86) par:
         while($fichier = readdir($dossier)){
          if($fichier != '.' && $fichier != '..' && $fichier != 'folder.php'){
           if ($passer > 0) {
         $passer--;
           }
           else
           {
            $nb_fichier++;
           echo     '<tr>
              <th> <a href="'. $root_dir.$fichier . '" rel="nofollow noopener noreferrer" target="_blank">'. $root_dir.$fichier . ' </th>
              <th>' . taille($root_dir.$fichier) . '</th>
              <th>'.date("d/m/20y", filectime($root_dir.$fichier)).' à '.date("H:i", filectime($root_dir.$fichier)).'</th>
              <th><a href="./ftp/' .$fichier . '" rel="nofollow noopener noreferrer" target="_blank" download="' . $fichier . '"><center><img src=""quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;download.png"></a></center></th>
              <th>'.actionfichier($fichier).'</th>
              <th>'.substr(strrchr($fichier, '.'), 1 ).'</th>
              </tr>';
            }
            }
           }

        Si cela fonctionne bien, tu ne devrais pas observer de changement de comportement.
        Cependant, si tu ajoutes
        ?passer=4
        à la fin du lien quand tu appelles ta page, la page devrait commencer à afficher le cinquième fichier, en passant les 4 premiers. (exemple: [[[http://ftp.fareoh.fr/folder.php?passer=4%5D%5D%5D )
        Cela donne quoi?
        0
      3. la pour l'instant j'ai une erreur..
        Parse error: syntax error, unexpected 'if' (T_IF) in /var/www/wkmfc8/www/ftp/folder.php on line 28
        0
      4. Contributeur Ambassadeur
        J'ai modifié ensuite, il manquait un ; en fin de première ligne.
        encore modifié, manquait ) en seconde ligne.
        0
      5. toujours la même erreur
        0
    2. Contributeur Ambassadeur
      <html>
       <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Fareoh.fr - FTP</title>
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="stylesheet" href="http://fareoh.fr/assets/css/main2.css" />
        <link rel="icon" type="image/png" href="http://dev.fareoh.fr/img/favicon.png" />
       </head>
       <body id="top">
         <header id="header">
          <div class="content">
           <br /><br />
             <form>
         <table style="width:100%; border:2;font-size:10px;">
         <tr style=" border:solid, black;" >
          <th><b>Nom</b></th>
          <th><b>Taille</b></th> 
          <th><b>Upload</b></th>
          <th><b>Télécharger</b></th>
          <th><b>Action</b></th>
          <th><b>Type</b></th>
          </tr>
      <?php
      $nb_fichier = 0;
      $root_dir='./ftp/';
      $passer = 0;
      if ( isset ($_GET['passer']) )
       if (intval($_GET['passer']) > 0)
        $passer=intval($_GET['passer']);
      
      function actionfichier($fichier) {
          $type = substr(strrchr($fichier, '.'), 1 );
          if ($type == 'osu' or $type == 'osz' or $type == 'rar' or $type == 'zip' ) {
               return 'Aucune';}
          if ($type == 'mp3' or $type == 'wav' or $type == 'm4a' or $type == 'wmv' or $type == 'aac') {
              return '<a href"http://ftp.fareoh.fr/player_audio.php?value='.$fichier.'">Ecouter</a' ;}
          if ($type == 'png' or $type ==  'PNG' or $type == 'jpg'  or $type == 'JPG' or $type ==  "gif" or $type ==  "GIF" or $type == 'tiff' or $type == 'TIFF' or $type == 'BPM'or $type == 'bmp') {
       return '<a href="http://ftp.fareoh.fr/visionneuse?value='.$fichier.'" rel="nofollow noopener noreferrer" target="_blank">Voir</a>' ;}
          if ($type !== 'osu' or $type !== 'osz' or $type !== 'MP3' or $type !== 'mp3' or $type !== 'MP4' or $type !== 'mp4' or $type !== 'wmv' or $type !== 'WMV' or $type !== 'acc' or $type !== 'bpm' or $type !== 'BMP' or $type !== 'tiff' or $type !== 'tiff'
           or $type !== 'gif' or $type !== 'm4a' or $type !== 'jpg' or $type !== 'JPG' or $type !== 'png' or $type !== 'PNG' ){
          return 'Aucune' ;}
       if ($type == 'txt' or $type == 'TXT'){
       return '<a href="http://ftp.fareoh.fr/txt.php?value='.$fichier.'" rel="nofollow noopener noreferrer" target="_blank">Lire</a>';}
      } 
      
        function taille($fichier){
          $taille = filesize($fichier);
          if ($taille >= 1073741824){
          $taille = round($taille / 1073741824 * 100) / 100 . " Go";
           }elseif ($taille >= 1048576){
          $taille = round($taille / 1048576 * 100) / 100 . " Mo";
           }elseif ($taille >= 1024){
          $taille = round($taille / 1024 * 100) / 100 . " Ko";
           }elseif ($taille > 0){
          $taille = $taille . " o";
           }else{
          $taille="-";
             }
          return $taille;
      }
        echo '<ul>';
      
      if($dossier = opendir($root_dir)){
       while($fichier = readdir($dossier)){
        if($fichier != '.' && $fichier != '..' && $fichier != 'folder.php'){
         if ($passer > 0) {
       $passer--;
         }
         else
         {
          $nb_fichier++;
         echo     '<tr>
            <th> <a href="'. $root_dir.$fichier . '" rel="nofollow noopener noreferrer" target="_blank">'. $root_dir.$fichier . ' </th>
            <th>' . taille($root_dir.$fichier) . '</th>
            <th>'.date("d/m/20y", filectime($root_dir.$fichier)).' à '.date("H:i", filectime($root_dir.$fichier)).'</th>
            <th><a href="./ftp/' .$fichier . '" rel="nofollow noopener noreferrer" target="_blank" download="' . $fichier . '"><center><img src=""quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;download.png"></a></center></th>
            <th>'.actionfichier($fichier).'</th>
            <th>'.substr(strrchr($fichier, '.'), 1 ).'</th>
            </tr>';
          }
          }
         }
       }
      echo '</ul>';
      $fichier_dir= ($root_dir.$fichier);
      ?>
          <th><a href="upname.php" rel="nofollow noopener noreferrer" target="_blank" style="font:14px;"><img src=""quot;"quot;"quot;"quot;upload.png" height="15px;" > Upload un nouveau fichier</a><i>  (sécurisé)</i></th> 
      
          </tr>
         </table>
      <?php closedir($dossier); ?>
       </form>
        <div style=" vertical-align:top;" ></div> 
           </div>
         </header>
         <footer id="footer">
          <ul class="icons">
           <li><a href="https://twitter.com/FareohAsc" rel="nofollow noopener noreferrer" target="_blank" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
          </ul>
          <p class="copyright">© Fareoh.fr 2017 </p>
         </footer>
         <script src=""quot;"quot;"quot;"quot;http://fareoh.fr/assets/js/jquery.min.js"></script>
         <script src=""quot;"quot;"quot;"quot;http://fareoh.fr/assets/js/jquery.scrolly.min.js"></script>
         <script src=""quot;"quot;"quot;"quot;http://fareoh.fr/assets/js/skel.min.js"></script>
         <script src=""quot;"quot;"quot;"quot;http://fareoh.fr/assets/js/util.js"></script>
         <script src=""quot;"quot;"quot;"quot;http://fareoh.fr/assets/js/main.js"></script>
      
       </body>
      </html>
      0
      1. Contributeur Ambassadeur
        suggestion pour le tout:
        <html>
         <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
          <meta http-equiv="X-UA-Compatible" content="IE=edge">
          <title>Fareoh.fr - FTP</title>
          <meta name="viewport" content="width=device-width, initial-scale=1" />
          <link rel="stylesheet" href="http://fareoh.fr/assets/css/main2.css" />
          <link rel="icon" type="image/png" href="http://dev.fareoh.fr/img/favicon.png" />
         </head>
         <body id="top">
           <header id="header">
            <div class="content">
             <br /><br />
               <form>
           <table style="width:100%; border:2;font-size:10px;">
           <tr style=" border:solid, black;" >
            <th><b>Nom</b></th>
            <th><b>Taille</b></th> 
            <th><b>Upload</b></th>
            <th><b>Télécharger</b></th>
            <th><b>Action</b></th>
            <th><b>Type</b></th>
            </tr>
        <?php
        $nb_fichier = 0;
        $root_dir='./ftp/';
        $passer = 0;
        if ( isset ($_GET['passer']) )
         if (intval($_GET['passer']) > 0)
          $passer=intval($_GET['passer']);
        
        function actionfichier($fichier) {
            $type = substr(strrchr($fichier, '.'), 1 );
            if ($type == 'osu' or $type == 'osz' or $type == 'rar' or $type == 'zip' ) {
                 return 'Aucune';}
            if ($type == 'mp3' or $type == 'wav' or $type == 'm4a' or $type == 'wmv' or $type == 'aac') {
                return '<a href"http://ftp.fareoh.fr/player_audio.php?value='.$fichier.'">Ecouter</a' ;}
            if ($type == 'png' or $type ==  'PNG' or $type == 'jpg'  or $type == 'JPG' or $type ==  "gif" or $type ==  "GIF" or $type == 'tiff' or $type == 'TIFF' or $type == 'BPM'or $type == 'bmp') {
         return '<a href="http://ftp.fareoh.fr/visionneuse?value='.$fichier.'" rel="nofollow noopener noreferrer" target="_blank">Voir</a>' ;}
            if ($type !== 'osu' or $type !== 'osz' or $type !== 'MP3' or $type !== 'mp3' or $type !== 'MP4' or $type !== 'mp4' or $type !== 'wmv' or $type !== 'WMV' or $type !== 'acc' or $type !== 'bpm' or $type !== 'BMP' or $type !== 'tiff' or $type !== 'tiff'
             or $type !== 'gif' or $type !== 'm4a' or $type !== 'jpg' or $type !== 'JPG' or $type !== 'png' or $type !== 'PNG' ){
            return 'Aucune' ;}
         if ($type == 'txt' or $type == 'TXT'){
         return '<a href="http://ftp.fareoh.fr/txt.php?value='.$fichier.'" rel="nofollow noopener noreferrer" target="_blank">Lire</a>';}
        } 
        
          function taille($fichier){
            $taille = filesize($fichier);
            if ($taille >= 1073741824){
            $taille = round($taille / 1073741824 * 100) / 100 . " Go";
             }elseif ($taille >= 1048576){
            $taille = round($taille / 1048576 * 100) / 100 . " Mo";
             }elseif ($taille >= 1024){
            $taille = round($taille / 1024 * 100) / 100 . " Ko";
             }elseif ($taille > 0){
            $taille = $taille . " o";
             }else{
            $taille="-";
               }
            return $taille;
        }
          echo '<ul>';
        $numfichier=$passer;
        $encore=0;
        if($dossier = opendir($root_dir)){
         while($fichier = readdir($dossier)){
          if($fichier != '.' && $fichier != '..' && $fichier != 'folder.php'){
           if ($passer > 0) {
         $passer--;
           }
           else
           {
            
         if ($nb_fichier=15)
         {
          $encore=$numfichier;
          break;
         }
         else
         {
          $nb_fichier++;
          $numfichier++;
             echo     '<tr>
                <th> <a href="'. $root_dir.$fichier . '" rel="nofollow noopener noreferrer" target="_blank">'. $root_dir.$fichier . ' </th>
                <th>' . taille($root_dir.$fichier) . '</th>
                <th>'.date("d/m/20y", filectime($root_dir.$fichier)).' à '.date("H:i", filectime($root_dir.$fichier)).'</th>
                <th><a href="./ftp/' .$fichier . '" rel="nofollow noopener noreferrer" target="_blank" download="' . $fichier . '"><center><img src=""quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;"quot;download.png"></a></center></th>
                <th>'.actionfichier($fichier).'</th>
                <th>'.substr(strrchr($fichier, '.'), 1 ).'</th>
                </tr>';
         }
            }
            }
           }
         }
        echo '</ul>';
        $fichier_dir= ($root_dir.$fichier);
        ?>
            <th><a href="upname.php" rel="nofollow noopener noreferrer" target="_blank" style="font:14px;"><img src=""quot;"quot;"quot;"quot;upload.png" height="15px;" > Upload un nouveau fichier</a><i>  (sécurisé)</i></th> 
        
            </tr>
           </table>
        <?php closedir($dossier); 
        if ($encore > 0)
        {
         echo '<br>'.'envoyer lien avec ?passer='.$encore.'<br>';
        }
        ?>
         </form>
          <div style=" vertical-align:top;" ></div> 
             </div>
           </header>
           <footer id="footer">
            <ul class="icons">
             <li><a href="https://twitter.com/FareohAsc" rel="nofollow noopener noreferrer" target="_blank" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
            </ul>
            <p class="copyright">© Fareoh.fr 2017 </p>
           </footer>
           <script src=""quot;"quot;"quot;"quot;http://fareoh.fr/assets/js/jquery.min.js"></script>
           <script src=""quot;"quot;"quot;"quot;http://fareoh.fr/assets/js/jquery.scrolly.min.js"></script>
           <script src=""quot;"quot;"quot;"quot;http://fareoh.fr/assets/js/skel.min.js"></script>
           <script src=""quot;"quot;"quot;"quot;http://fareoh.fr/assets/js/util.js"></script>
           <script src=""quot;"quot;"quot;"quot;http://fareoh.fr/assets/js/main.js"></script>
        
         </body>
        </html>
        0
        1. il n'y a rien dans le tableau .. :(
          0
        2. Contributeur Ambassadeur
          petite erreur:
          au lieu de
          if ($nb_fichier=15)
          ,
          il faut
          if ($nb_fichier==15)
          0
      2. Contributeur Ambassadeur
        j'ai aussi simplifié:
        function actionfichier($fichier) {
            $type = strtolower(substr(strrchr($fichier, '.'), 1 ));
            if ($type == 'mp3' or $type == 'wav' or $type == 'm4a' or $type == 'wmv' or $type == 'aac') {
                return '<a href"http://ftp.fareoh.fr/player_audio.php?value='.$fichier.'">Ecouter</a' ;}
            if ($type == 'png' or $type == 'jpg'  or  $type ==  "gif"  or $type == 'tiff' or $type == 'bpm'or $type == 'bmp') {
         return '<a href="http://ftp.fareoh.fr/visionneuse?value='.$fichier.'" rel="nofollow noopener noreferrer" target="_blank">Voir</a>' ;}
         if ($type == 'txt' ){
         return '<a href="http://ftp.fareoh.fr/txt.php?value='.$fichier.'" rel="nofollow noopener noreferrer" target="_blank">Lire</a>';}
        	   return 'Aucune' ;
        } 
        0
        1. Je te remercie de ton aide :)
          Tu peux aller voir mon travail sur http://ftp.fareoh.fr :)
          0
        2. Contributeur Ambassadeur
          pour ton info:
          [http://ftp.fareoh.fr/delete_auth.php?EOT=%5D
          donne une erreur
          Notice: Use of undefined constant EOT - assumed 'EOT' in /var/www/wkmfc8/www/ftp/delete_auth.php on line 5
          0
        3. Oui parce que la variable "Value" n'es pas envoyé ^^ ce n'es pas trop grave normalement on est sur cette page avec la variable
          0