Skip to content
Advertisement

How to remove/ignore .htaccess file from gallery feed

Good day! I’ve mafe an infinite scrolling gallery and it works as intended, php code supplies the the feed with images with this code (below) from the directory. However there is a problem, I can’t make this script to ignore htaccess file, so its 1 image which is always broken. How to disregard this file?

Here is my code:

 <?php
 
    $dir = "img";
    $allowed = array('jpeg', 'png', 'jpg');
    $ext = pathinfo($f, PATHINFO_EXTENSION);

    

        if(is_dir($dir)){
            if($dd = opendir($dir)){
                while (($f = readdir($dd)) !== false)
                  if($f != "." && $f != "..")
                      $files[] = $f;
                      $allowed = array('jpeg', 'png', 'jpg');
                      $ext = pathinfo($f, PATHINFO_EXTENSION);
                      closedir($dd);
        } 
     
 
        $n = $_GET["n"];
        $response = "";
            for($i = $n; $i<$n+9; $i++){
                $response = $response.$files[$i%count($files)].';';
            }
            echo $response;
        }
     
?>

Thank you!

Advertisement

Answer

Well, just add another check for .htaccess and use in_array() for better code clarity.

You can change

if($f != "." && $f != "..")

to

if(!in_array($f,[".","..",".htaccess"]))
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement