Jump to content

Recommended Posts

Hi,

 

I am using this script to create a gallery array

 

<?
$login = $_GET['login'];	
$dir ="http://www.mmm.co.uk/clients/$login/";
include "/var/www/vhosts/mmm.co.uk/httpsdocs/scripts/connection.php"; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../../styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script src="getpics.php?dir=<? echo $dir; ?>" type="text/javascript"></script>
<script type="text/javascript">

var dimension="1x20" //Specify dimension of gallery (number of images shown), such as 4x2, 3x1 etc
var imagepath="<? echo $dir ?>" //Absolute path to image directory. Include trailing slash (/)
var href_target="order" //Enter target attribute of links, if applicable

var popupsetting=[0, ""]

var descriptionprefix=[0, " "]

var gsortorder=""

/////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)

else
galleryarray.sort();

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

function buildimage(i){
var imagecompletepath='dis.php?login=<?php echo $login; ?>&image=<? echo $dir ; ?>/'+galleryarray[i][0]+''
var tempcontainer='<table align="center"><tr><td>'
tempcontainer+='<a href="'+imagecompletepath+'" target="'+href_target+'" onClick="return popuplinkfunc(this)">'
tempcontainer+='<img src="'+imagepath+galleryarray[i][0]+'" title="'+galleryarray[i][0]+'"/>'
tempcontainer+='</a></td></tr><tr><td class="image">'+galleryarray [i][0]+'</td></tr><tr><td><hr /></td></tr></table>'
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('')
}

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('<span class="main"><a id="navlink'+i+'" href="javascript:jumptopage('+i+')\">['+i+']</a></span> ')
document.getElementById("navlink1").className="current"
</script></div>
</body>
</html>

 

Only issue is, that it doesnt find any .jpgs to create an array of :(

 

i get this error:

 

Line 101

Char 11

 

GalleryArray is undefined

 

thats in the javascript error box, but its something to do with the data passing through.

 

this is the getpics.php page

<?
Header("content-type: application/x-javascript");
function returnimages() { 
   $dirname=. $_GET["dir"]; 
   $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();
?>

 

Its 6am, ive been working for 14 hours now, and im starting to lag a little, can you see anything obvious?

 

Cheers guys :)

Link to comment
https://forums.phpfreaks.com/topic/98759-array-is-empty/
Share on other sites

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.