Jump to content

Recommended Posts

My earlier post resulted in some good advice on showing photos from a folder.

 

This works very well:-

<html>
<body>
<h1 align="center">Family Photos</h1>
<?php
$dirname = "img/";
$images = glob($dirname."*.png");
foreach($images as $image) {
     Echo '<img src="'.$image.'"/>';
}
?>

But how can I also show the file name under the picture?

I have the code to extract the file name from the complete path.

 

Link to comment
https://forums.phpfreaks.com/topic/286845-show-text-below-a-picture/
Share on other sites

Thanks, but the text appears alongside the image, not underneath.

Here's what I'd like to see!

 

2390736357.jpg
2390736357.jpg
(100 x 67 pixels)
image/jpeg
2390735019.jpg
2390735019.jpg
(100 x 67 pixels)
image/jpeg
2390370487.jpg
2390370487.jpg
(79 x 80 pixels)
image/jpeg
2390737530.jpg
2390737530.jpg
(100 x 67 pixels)
image/jpeg
2397734534.jpg
2397734534.jpg
(100 x 56 pixels)
image/jpeg
 
 
 
 
 
 
 
 
 
This is from http://www.the-art-of-web.com/php/dirlist/1/ but I can't follow the html stylesheet stuff.

This didn't work:-

<html>
<body>
<h1 align="center">Family Photos</h1>
<?php
$dirname = "img/";
$images = glob($dirname."*.png");

foreach($images as $img) {
<div>
  echo '<img src= "'.$img.'" />'; 
  echo "XXX"
</div>
}

?>

Its possible that div is html and not php, found a post that suggests using   echo "<div>";

But that doesn't work either

Normally I don't provide such help to someone who doesn't apparently have a clue, but here goes:

 

 

<?php
echo "<html><body>";
echo  "<center><h1>Family Photos</h1></center>";
$dirname = "img/";
$images = glob($dirname."*.png");
foreach($images as $img)
{
    $img_cap = "???";
    echo "<div><img src='$img'><br>$img_cap</div>";
}
 
?> 

 

Where are you going to get the captions for each image as you cycle thru them?

I was being facetious since I don't think you can.  (But I could be wrong.)

 

If I were doing it I would capture the comment from the file upload page and then store the image in my images folder and at the same time save the comment in a table under the image's saved name, obviously checking the table before both actions to ensure that I don't have a dupe image name.  I would also store some other pertinent data in the table too, such as date added, contributor(?) name or id, dimensions (w/h), and maybe a keyword or two to provide some rudimentary search capabilities.

 

Then my display page (that we just worked on) would use a query instead of a glob to get the image names (and comments) and then build the page.

I was being facetious also.

This is where I am.

I have several hundred scanned photos stored offline and managed by a mysql database.  All the photos have associated thumbnails and descriptive info is held in the database.

This is the sort of thing I've been doing for a long time but there came the need to share the info online.  Hence my first venture into php, html etc.

I already have a login page that manages user id & password through mysql and I can import info from my local db.

The next step is to present the thumbnails on the web in a presentable manner PLUS a caption underneath.  As you observe, just the photo name (which in my case is unique) will do.

After that I was I hoping to use the 'onhover' to display the full information and then click to display a larger image.

Sounds like you are where you want to be.  The hover and accompanying text display as well as the click to a larger image are a POC - with JavaScript.

 

Please tell me that you didn't store any images in your db.  Not recommended at all.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.