THIS IS WHAT I'M DOING:
I have a PHP code that runs and echo's out all the images it finds in a directory (folder on my site). The codes to show these images are below. It's a thumb image inside a link to the bigger image (I'm using lightbox to show them).
// These are my variables
$base = "folder location that all albums are stored in";
$thumbs = "folder location that the thumbs are stored in";
$get_album = "the name of the album the user choose to look at";
$images = "all the images found in this album";
// Now using a while loop every image is echo'd out with this code
echo "<table class='showthumbs'><a href='$base/$get_album/$images' rel='lightbox[1]' title='{$images}' /><img src='$base/$thumbs/$images'' />[/url]
</td></tr></table>";
NOW THIS IS WHAT I WANT TO DO:
If you look at the TITLE tag in the code you'll notice it look like this... {$images} ...I would like to know how to do the following to this:
1) Once the original script is done, a new one (the one we're working on now) searches the page for... { } ...just the brackets and does the next step to them
2) Grab whats in it and add it to a new variable (Example: image_1.jpg) , then switch the files extension (Example: image_1.txt or image_1.php), now move on to step 3
3) NOW look inside a folder location I designate and look for a file that has this name (Example: We change image_1.jpg to image_1.txt and tell the script to look in folderA for it). Once a file is found with that name get the file contents (just the text) and replace the {} and what was inside them in step one with this text.
OVERVIEW - I know this isn't as hard as it sounds I just need some help. WHEN a person uploads an image to my site three things happen. Main image is saved in a folder, thumb image is saved in a folder, and the description is saved in a folder. BOTH the thumb and main image have the same name and extension still but the description only shares the same name, different extension.
I'm trying to get this third file, the description, to display in the title tag of the appropriate image it belongs too.
HERE IS THE ENTIRE CODE FOR YOU TO LOOK AT:
<?php
// Give the current page location (This is so all our links will work later when we embed into pages)
$page = $_SERVER['PHP_SELF'];
// Directories (Where all the albums will be stored)
$base = "../scripts/album/assets";
$thumbs = "thumbs";
$text = "text";
$lightbox = "lightbox";
// Settings
$column = "4";
// Get album thats asked for
$get_album = $_GET['album'];
// Show list of albums first if they havn't selected one, else jump to end of script
if (!$get_album)
{
// Set up a list of the albums (look in the directory)
echo "Select an album:<br />";
$handle = opendir($base);
while (($albums = readdir($handle))!==FALSE)
{
// Clean up the directory so only actual albums show
if (is_dir($base."/".$albums)&&$albums!="."&&$albums!=".."&&$albums!=$thumbs&&$albums!=$lightbox&&$albums!=$text)
{
// Now show a list of albums they can choose
echo "<a href='$page?album=$albums'>$albums</a><br />";
}
}
closedir($handle);
}
// SECOND PART - album has been selected
else
{
// They already picked an album or just did, so show it (opens dir and selects folder choosen)
if (!is_dir($base."/".$get_album)||strstr($get_album,".")!=NULL||strstr($get_album,"..")!=NULL||strstr($get_album,"/")!=NULL||strstr($get_album,"\\")!=NULL)
{
// Security feature, if statment checked for bad stuff and will send them here if anythings wrong
echo "This album doesn't exist.";
}
else
{
// Create whats needed to show album
// This is starting a column count (that way we can limit how many pictures show per line)
$x = "0";
echo "<table id='albumtitletable'><tr><td><span id='albumtitlespan'>Viewing Album: $get_album</span><span class='backalbum'><a href='$page'>Back to Albums</a></span></td></tr></table><br />";
$handlenew = opendir($base."/".$get_album);
echo "<table id='forcethumbscenter'><tr><td>";
while (($images = readdir($handlenew))!==FALSE)
{
// Check that nothing bad is happening such as code injections, show album (using an IF NOT check)
if ($images!="."&&$images!="..")
{
// Show images
echo "<table class='showthumbs'><tr><td><a href='$base/$get_album/$images' rel='lightbox[1]' title='[$images]' /><img src='$base/$thumbs/$images' height='140' width='135' /></a><br /><span class='thumbstext'>Click to Enlarge</span></td></tr></table>";
// Add 1 to X every time a new picture is displayed
$x++;
// Once X is equal to the variable of $column at the start, break down and start new row
if ($x==$column)
{
echo "<br />";
// Restart count
$x = "0";
}
}
}
closedir($handlenew);
include ("../scripts/replacedes.php");
echo "</td></tr></table>";
echo "<br /><span class='backalbum'><a href='$page?album=$get_album#embedalbumbox'>Return to Top</a> | <a href='$page'>Back to Albums</a></span>";
}
}
?>