Minggu, 01 November 2015

Php Code : How To Show Images From A Folder

Php Code: How To Display Images From A Folder Using Php

________________________________________________________


In this Php Tutorial we will Learn How To Get And Display Only Images From A Directory Using Php .

I Use In This Tutorial:
- NetBeans IDE .
- XAMPP .



 




Php Source Code:

<?php

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

if(is_dir($dir_path))
{
    $files = scandir($dir_path);
    
    for($i = 0; $i < count($files); $i++)
    {
        if($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>";
            }
        }
    }
}





                     
php show image




Bagikan

Jangan lewatkan

Php Code : How To Show Images From A Folder
4/ 5
Oleh

Subscribe via email

Suka dengan artikel di atas? Tambahkan email Anda untuk berlangganan.