Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Retrieving an array of images on HTML page using PHP

images php coding issues or problems here.

Moderators: macek, egami, gesf

Retrieving an array of images on HTML page using PHP

Postby chevalier51 » Sat May 05, 2012 3:54 am

I am retrieving images from a directory using php. Images are displayed on PHP page (getUser.php) but how can these images be display on any HTML.
getUser.php

Code: Select all
<?php


$dir = 'images';
$file_display = array('jpg','jpeg','png','gif');

if (file_exists ($dir) == false) {
    echo 'Directory \'', $dir, '\' not found!';
}
else{
    $dir_contents = scandir($dir);


    foreach($dir_contents as $file) {
        $file_type = strtolower(end(explode('.', $file)));

        If($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) {
            echo '<img src="', $dir, '/', $file, '" alt="', $file, '" />';
            /*echo '<td>';
echo '<img src =';
echo $dir."/".$file;
echo  '/>';
echo '</td>'; */

        }       

    }

}


?>


one.html
I want this array of images to be displayed in html (div). That is the source of the image tag takes reading from the PHP file. I have done this in ASP.NET but can't figure it out in PHP Is there anything like

Code: Select all
<img src="images/vimages/<%=row["image"] %>"
ASP.NET

this PHP.
Code: Select all
<div id="pics">
                <img src="img/...jpg" alt=""  />

</div>



The above div will be dynamically populating using getUser.php file.
chevalier51
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat May 05, 2012 3:44 am

Re: Retrieving an array of images on HTML page using PHP

Postby macek » Mon May 07, 2012 12:45 am

Code: Select all
<div id="pics">
                <img src="img/<?php echo $image; ?>" alt=""  />

</div>
User avatar
macek
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron