I have been making a blog, but I have a problem. I can't display image from folders images. I need to display one image every time when name and comment put on the page. Every time another image and need to stay on page.
Here is link
http://slimhamdi.net/lina/demos/blog-post-dark.html?name=hhhhhhh&email=hh%40hotmail.com&comment=h&send=
I need same like this blog, I would like to avoid MySQL. Any help will be appreciated.
<?php
$images = array("user1.jpg", "user2.jpg", "user1.jpg");
$images = glob('images/*');
shuffle($images );
foreach($images as $image ) {
break;
}
?>
<img src="<?php echo "$image"; ?>" />
why do you use break in foreach?
you should echo the img tag in foreach
if your images are in images folder, you shouldn't you glob, and instead you can concat it to path.
<?php
$images = array("user1.jpg", "user2.jpg", "user1.jpg");
shuffle($images);
foreach($images as $image ) {
echo "<img src='images/{$image}' />";
}
?>
You are overwriting variables:
<?php
$images = array("user1.jpg", "user2.jpg", "user1.jpg");
$images = glob('images/*'); // Overwrites the previous $images
That way the $images
in the foreach
is something else.
There is also no need to use a break
in the foreach
loop
<?php
$images = array("user1.jpg", "user2.jpg", "user1.jpg");
shuffle($images );
foreach($images as $image ) {
echo '<img src="'.$image.'" />';
//echo '<img src="images/'.$image.'">';// With file path
}