Jump to content

Archived

This topic is now archived and is closed to further replies.

BorysSokolov

Displaying Images From Array Using PHP/HTML

Recommended Posts

I have several images in a directory, which I would like to output(in an organized way) to the page. I've tried reading all the directory contents, and loading their names into an array to display the images using HTML, but I can't for the life of me figure out how to then position the pictures correctly in CSS.

 

Here's the code:

 

<?php
$dirLoc = 'myWebsite/galleryPics';
$handle = opendir($dirLoc);


while($readDir = readdir($handle)){
if($readDir != '.' && $readDir != '..'){
$pic[] = $readDir;
}
}


foreach($pic as $k){
echo "<div class = \"picsDiv\">";
echo "<img src = \"$dirLoc/$k\" height = \"100px\" width = \"100px\"/></div>";
}
?>


<html>
<head>
<style type = "text/css">

.picsDiv {width:150px;
 height:150px;
 border:1px solid red;
 background-color:grey;}

img {position:relative;
 top:50%;
 left:50%;
 margin-top:-50px;
 margin-left:-50px;}
</style>
</head>
</html>

 

Thank you in advance for any feedback.

Share this post


Link to post
Share on other sites

What is "correctly" supposed to be? How does it look now and how do you want it to look?

Share this post


Link to post
Share on other sites

What is "correctly" supposed to be? How does it look now and how do you want it to look?

 

At the moment the images are positioned in a single, straight, vertical column, with no spaces in between them. I'd like them, however, to run left to right, skipping to the next line once there's no more space, with some space separating them; like a typical grid layout.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.