display html files from a directory in a php

2

I have a directory with html files that are articles (no header or footer, I want to show all those html files in a php called articles.php with a link to access them (the article.php file has a header and footer by require ()

Finally, what I want is to show the article as articulo.php? articulpo.html but with the header and footer of the article php file

    
asked by Marlon Camacho Polo 14.07.2016 в 17:53
source

2 answers

3

For this question, I'm going to imagine that your website has a structure like this (it's probably a bit different, adapting the code should to your structure should be simple):

/
├ index.php
├ articulo.php
├ encabezado.php
├ pie.php
└ articulos/
     ├ articulo1.html
     ├ articulo2.html
     ├ articulo3.html
     ├ ...

In your file articulo.php is where you have the header and foot with a require() , then what you should do is the following:

  • Pass the article that you want included in the header
  • Read in% co_of% what article
  • Add the article's html using $_GET or require() (as you're already doing for the header and footer)
  • Whereas the article would be passed in the header as follows: include() , then this would be done as follows in articulo.php?articulo=articulo1 ,:

    <?php
    
        // incluimos la cabecera
        require("cabecera.php");
    
        // si se ha pasado el articulo y existe su fichero html
        $articulo = filter_input(INPUT_GET, "articulo"); 
        if (isset($_GET["articulo"]) && file_exists("articulos/$articulo.html")) {
            // se incluye en la página
            require("./articulos/$articulo.html");
        } else {
            // si no se ha pasado id del artículo o no existe, se muestra un error
            echo "Artículo no especificado o no existente.";
        }
    
        // incluimos el pie
        require("pie.php");
    
        
    answered by 14.07.2016 в 22:16
    0
    $extension = ".html";
    
    
    
    $directorio = '/tmp';
    $dir = opendir($directorio);
    
    while ($archivo = readdir($dir)){
     if (!is_dir($archivo)){//Validamos q no se abra otra carpeta
        if(strpos($archivo, $extension)){
          ///SE ENCONTRO ARCHIVO HTML
        }
     }
    }
    
        
    answered by 14.07.2016 в 18:30