/    Sign up×
Community /Pin to ProfileBookmark

modify gallery script to attach .txt description to each images

hello

This script basically scan a folder for pictures so someone can just drop this php in a folder filled with picture to get a picture gallery automatically.

i’m trying to modify this script so when it return the name of the images, it get a description for the image from a text file of the same name (or xml or whatever) so that description can go in the <title> tag of the picture in the gallery.

so that you have in the folder
1.jpg = picture
1.txt = description that will go in the <title> tag

I’m very new at this and i’m afraid i can’t figure it out.

Please help me!

ps: yes i’m a beginner; but doing something about it ?

———–this is the php——————

[CODE]<?
Header(“content-type: application/x-javascript”);

function returnimages($dirname=”.”) {
$pattern=”.(jpg|jpeg|png|gif|bmp)$”;
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
$filedate=date (“M d, Y H:i:s”, filemtime($file));
echo ‘galleryarray[‘ . $curimage .’]=[“‘ . $file . ‘”, “‘.$filedate.'”];’ . “n”;
$curimage++;
}
}

closedir($handle);
}
return($files);
}

echo “var galleryarray=new Array();” . “n”;
returnimages();
?>[/CODE]

—————this is the html——————-

[CODE]
/***********************************************
* PHP Photo Album script- &#194;&#169; Dynamic Drive DHTML code library ([url]www.dynamicdrive.com[/url])
* Visit [url]http://www.dynamicDrive.com[/url] for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/

var dimension=”4×2″ //Specify dimension of gallery (number of images shown), such as 4×2, 3×1 etc
var imagepath=”http://www.mysite.com/largegallery/” //Absolute path to image directory. Include trailing slash (/)
var href_target=”new” //Enter target attribute of links, if applicable

//Toggle popup link setting: popupsetting[0 or 1, “pop up window attributes” (if 1)]
var popupsetting=[1, “width=500px, height=400px, scrollbars, resizable”]

//Toggle image description: descriptionprefix[0 or 1, “Text to show” (if 1)]
var descriptionprefix=[0, “Photo “]

//Sort images by date? (“asc”, “desc”, or “”)
//”desc” for example causes the newest images to show up first in the gallery
//”” disables this feature, so images are sorted by file name (default)
var gsortorder=””

//By default, each image hyperlinks to itself.
//However, if you wish them to link to larger versions of themselves
//Specify the directory in which the larger images are located
//The file names of these large images should mirror those of the original
//Enter a blank string (“”) to disable this option
var targetlinkdir=”http://www.mysite.com/largegallery/”

/////No need to edit beyond here///////////////////

function sortbydate(a, b){ //Sort images function
if (gsortorder==”asc”) //sort by file date: older to newer
return new Date(a[1])-new Date(b[1])
else if (gsortorder==”desc”) //sort by file date: newer to older
return new Date(b[1])-new Date(a[1])
}

if (gsortorder==”asc” || gsortorder==”desc”)
galleryarray.sort(sortbydate)

var totalslots=dimension.split(“x”)[0]*dimension.split(“x”)[1]

function buildimage(i){
var imagecompletepath=(targetlinkdir!=””)? targetlinkdir+galleryarray[i][0] : imagepath+galleryarray[i][0]
var tempcontainer='<a href=”‘+imagecompletepath+'” target=”‘+href_target+'” onClick=”return popuplinkfunc(this)”>’
tempcontainer+='<img src=”‘+imagepath+galleryarray[i][0]+'” title=”‘+galleryarray[i][0]+’ [‘+galleryarray[i][1]+’]” />’
tempcontainer+='</a><br />’
tempcontainer+=(descriptionprefix[0]==1)? descriptionprefix[1]+(i+1) : “”
return tempcontainer
}

function jumptopage(p){
var startpoint=(p-1)*totalslots
var y=1;
for (i=0; i<totalslots; i++){
document.getElementById(“slide”+i).innerHTML=(typeof galleryarray[startpoint+i]!=”undefined”)? buildimage(startpoint+i) : “”
}
while(document.getElementById(“navlink”+y)!=null){
document.getElementById(“navlink”+y).className=””
y++
}
document.getElementById(“navlink”+p).className=”current”
}

var curimage=0
for (y=0; y<dimension.split(“x”)[1]; y++){
for (x=0; x<dimension.split(“x”)[0]; x++){
if (curimage<galleryarray.length)
document.write(‘<div id=”slide’+curimage+'” class=”slideshow”>’+buildimage(curimage)+'</div>’)
curimage++
}
document.write(‘<br style=”clear: left” />’)
}

function popuplinkfunc(imgsrc){
if (popupsetting[0]==1){
var popwin=open(imgsrc.href, “popwin”, popupsetting[1])
popwin.focus()
return false
}
else
return true
}

</script>

<!–Below HTML code refers to the navigational links for the gallery–>

<div id=”navlinks”>
<script type=”text/javascript”>
for (i=1; i<Math.ceil(galleryarray.length/totalslots)+1; i++)
document.write(‘<a id=”navlink’+i+'” href=”javascript:jumptopage(‘+i+’)”>Page’+i+'</a> ‘)
document.getElementById(“navlink1″).className=”current”
</script>[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@LeeUFeb 24.2009 — Please don't cross post. The other thread has been removed
×

Success!

Help @patbb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...