Displaying images in a directory

I have a script to display all images in a directory…I tried to modify it to make them links

<?php
$files = glob("images/gallery/gallery2/thumbs/*.*");

for ($i=1; $i<count($files); $i++)

{

$image = $files[$i];
echo '<a href="'.$image.'" rel="prettyphoto[gallery1]">';
echo '<img src="'.$image .'" alt="Gallery #2" />';
echo "</a>";
}
?>

its at

The problem is the correct link is to each image of the same name in the directory above it
(not in the same directory as they are now)
How do I modify the first echo statement to point to the parent directory?

So like this?

echo '<img src="../'.$image .'" alt="Gallery #2" />';

Each …/ before the src will move up a directory.

its that easy, thanks again ryan

I spoke too soon. Since the link has to move up a directory (not the src of the image) I tried to put the …/. at the href with no luck. Is there a way to point the link and not the image in (but using PHP)

<a href="images/gallery/gallery1/thumbs/10155905_701384769903886_388354013594823396_n.jpg" rel="prettyphoto[gallery1]"><img src="images/gallery/gallery1/thumbs/10155905_701384769903886_388354013594823396_n.jpg" alt="Gallery #1" /></a>

THe …/ should allow you to move up a directory as well. There should have been no issue.

You could always make links like href=“/rootfolder/images/image.jpg”. That beginning / means to start at the root directory and go from there.

I do it that way and it helps me know exactly where I’m pointing. I can also move files easier.

what you said before is exactly what I was thinking as the solution

<?php
$files = glob("images/gallery/gallery1/thumbs/*.*");

for ($i=1; $i<count($files); $i++)

{

$image = $files[$i];
echo '<a href="../'.$image.'" rel="prettyphoto[gallery1]">';
echo '<img src="'.$image .'" alt="Gallery #1" />';
echo "</a>";
}
?>

But this is the result

the links don’t work
If I start with the root folder, dont I still have the problem of removing thumbs from the href?

One thing I’ve realized about working with prettyphoto through my work, is that the URL reference points you try aren’t loading what you want. E.g. the prettyphoto is loading up a specific page from a specific URL and your image src must base its path off of the URL that it tries to load. E.g. if you load up a page in a folder 3 levels deep, and you try to reference images like "src=“image.jpg” it will find the image from the loaded page that is 3 folders down. It’s weird like that.

So your outputted HTML must be standardized and reference it universally. Like so.

<a href="/kindergarten-template/HTML/images/gallery/gallery1/thumbs/10171662_701384483237248_3194049743468936439_n.jpg" rel="prettyphoto[gallery1]"><img src="/kindergarten-template/HTML/images/gallery/gallery1/thumbs/10171662_701384483237248_3194049743468936439_n.jpg" alt="Gallery #1"></a>

Jeez…
What a dumb system, but made the change,

<?php
$files = glob("images/gallery/gallery1/thumbs/*.*");

for ($i=1; $i<count($files); $i++)

{

$image = $files[$i];
echo '<a href="/kindergarten-template/HTML/'.$image.'" rel="prettyphoto[gallery1]">';
echo '<img src="/kindergarten-template/HTML/'.$image .'" alt="Gallery #1" />';
echo "</a>";
}
?>

I think the best way to do this is something like

<?php
$thumbs = "images/gallery/gallery1/thumbs/";
$imgs = "images/gallery/gallery1/";

$files = glob($thumbs."*.*");

for ($i=1; $i<count($files); $i++)

{

$image = $files[$i];
//how do I point it to the other directory?
echo '<a href="/kindergarten-template/HTML/'.$image.'" rel="prettyphoto[gallery1]">';
echo '<img src="/kindergarten-template/HTML/'.$image .'" alt="Gallery #1" />';
echo "</a>";
}
?>

Very dumb - it stumped me for quite a bit when I first came across this issue. I can almost see why it will load the image from the loaded URL path but doesn’t mean I like it or want it.

I could just use HTML, but thought PHP would have a better system…
Oh well

found somewhat of a solution,

<?php
foreach(glob("images/gallery/gallery4/thumbs/".'*') as $filename){
echo '<a href="images/gallery/gallery4/'.basename($filename).'" rel="prettyphoto[gallery1]">';
echo '<img src="images/gallery/gallery4/thumbs/'.basename($filename) .'" alt="Gallery #4" />';
echo "</a>";
}
?>

Having them all be
`alt=“Gallery #4
isn’t really in the spirit of “alt”.

Would it not be better to at least append the filename if not better descriptions?`

As far as paths are concerned I call a config file and set constants.

define('LOCALHOST', 'localhost' === $_SERVER['SERVER_NAME'] );

If(LOCALHOST){
  define('PATH_IMAGES', 'this_path');
}else{
  define('PATH_IMAGES', 'that_path');
}

Only one file required that works on localhost and online.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.