samedi 3 octobre 2020

Reading file directly from folder in php

I want my code to read the file(image) from directly from the folder. But only one file(image) it read and still reading it again (infinity) it didn't stop display one same file(image). But not all the other five different files (image).

        <?php

        $dir_path = "image/gundam/";
        $extensions_array = array('jpg','png','jpeg');

        if(is_dir($dir_path))
        {
            $files = scandir($dir_path);

            for($i = 0; $i < count($files); $i++)
            {
                while($files[$i] !='.' && $files[$i] !='..')
                {
                    // get file name
                    echo "File Name -> $files[$i]<br>";

                    // get file extension
                    $file = pathinfo($files[$i]);
                    $extension = $file['extension'];
                    echo "File Extension-> $extension<br>";

                   // check file extension
                    if(in_array($extension, $extensions_array))
                    {
                    // show image
                    echo "<img src='$dir_path$files[$i]' style='width:100px;height:100px;'><br>";
                    }
                }
            }
        }
        ?>



Aucun commentaire:

Enregistrer un commentaire