Pergunta

Please, can somebody help me? I have a Parse error: syntax error, unexpected end of file on line 83 but don`t know why. the code is this:

<!DOCTYPE html>

<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">

    <title></title>
</head>

<body>
    <?php
        header('Content-type: text/html; charset=utf-8');

        $path = 'fotos'; # Directorio donde están las imágenes
        $limit = 4; # Cuantas imágenes se mostraran por pagina
        $limit_file = 5; # Imágenes a mostrar por linea en la tabla
        $n = 0;
        $desde;
        $hasta;
        # Comprobamos si es un directorio y si lo es nos movemos a el
        if (is_dir($path)){
            $dir = opendir($path);
            # Recorremos los ficheros que hay en el directorio y cogemos solamente aquellos cuya extensión
            # sea jpg, gif y png y la guardamos en una lista
            while (false !== ($file = readdir($dir))) {
                if (preg_match("#([a-zA-Z0-9_\-\s]+)\.(gif|GIF|jpg|JPG|png|PNG)#is",$file)){
                    $list[] = $file;
                }
            }

            # Cerramos el directorio
            closedir($dir);
            # Ordenamos la lista
            sort ($list);
            # Contamos el total de elementos en la lista
            $total = count($list);
            $paginas = ceil($total/$limit);
            if (!isset($_GET['pg'])){
                $desde = 0;
                $hasta = $desde + $limit;
            }else if((int)$_GET['pg'] > ($paginas-1)){
                # Si pg es mayor que el total de paginas se muestra un error
                echo "<b>No existe esta pagina en la galería</b>
                  <a href='galeria.php'>Volver a la galería</a>";
                die();
            }else{
                $desde = (int)$_GET['pg'];
            }
            # Y generamos los enlaces con los thumbnails
            for ($i=($desde*$limit);($i!=$total) && ($i<($desde*$limit)+$limit);$i++){
                # Comprobamos si existe en la lista una llave con el valor actual de $i para evitar errores
                if(array_key_exists($i, $list)){
                    echo "<td><a href='$path/$list[$i]'><img src='thumb.php?img=$path/$list[$i]' /></a>
                      </td>\n";
                    $n++;
                    if ($n == $limit_file){
                        echo "</tr>\n<tr>\n";
                        $n = 0;
                    }
                }
            }
        }else{
            echo "$path no es un directorio";
        }

        echo "</tr>";
        echo "</table>";
        echo "<p id='paginas'>";

        # Generamos un listado de las paginas de la galería
        for ($p = 0; $p<$paginas; $p++){
            $pg = $p+1;
            if ($p == $desde){
                echo "$pg ";
            }else{
                echo "<a href ='?pg=$p'>$pg</a> ";
            } 

            echo"</p>";
            echo "Hay un total de $total imagen(es) en $paginas paginas(s)" ;
    ?>
</body>
</html>

The code is supposed to show the list of images in a paged, ie if you have more than X images, viewing these X and down come the links to other pages.

Foi útil?

Solução

Your for-loop, for ($p = 0; $p<$paginas; $p++){, doesn't end anywhere.

Outras dicas

Your braces don't match - the for loop doesn't have a closing brace.

Unexpected end of file just means that PHP reached the end of the file but was expecting something else - in this case a closing brace.

no clossing bracket for the 'for' loop

  # Generamos un listado de las paginas de la galería
    for ($p = 0; $p<$paginas; $p++){

You should close your for loop like this :-

for ($p = 0; $p<$paginas; $p++){
     $pg = $p+1;
     if ($p == $desde){
      echo "$pg ";
     }else{
      echo "<a href ='?pg=$p'>$pg</a> ";
     } 
}                                                // close for loop
    echo"</p>";
    echo "Hay un total de $total imagen(es) en $paginas paginas(s)" ;
     ?>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top