I dont know if this has been up in the forum.

I am currently building a picture gallery.
And I am searching a directory and listing all files it found in an array named phparray.

With this array I must somehow use it to view the pictures it found, and this must be done with javascripts.

I am using the echo function to return phparray[nr]
but this number (nr-) wont count up, I have tried to do the counter with javascripts, and with php but it wont count up.

my currently count function is:
$nr=$nr+1

but somehow this wont work.
Is there some other way to do it?

    Well count the number of files in the directory.. then

     
    
    for ($i=1; $i<$count; ++$i)
    while($i<($count))
    {
    echo phparray[$i];
    
    $i++;
    }
    

    Or something along those lines probably....

      Well, I have tested this but someway this wont work.

        Ok, you have an array full of paths to the images right ? I mean u have the image names in this array right ?

        After you have the array done try that:

        <SCRIPT Language="JavaScript">
        <? for($x=0;$x<count($YourArray);$x++) { ?>

        var MyImages[<?=$x;?>] = '<?=$YourArray;?>';

        <? } ?>
        </script>

        This should transfer you data to the client side, i mean, store all the image names to a JAVASCRIPT ARRAY

        Now you can easylly change your images ...

        Insert the tag for img where you image will be showed:
        <IMG SRC="" name="Display">

        To change this image to another use something like

        document.Display.src = MyImages[n];

        in any point you want ...

          a month later

          here's the code I use for my gallery, It's simple and easy. No database just upload jpg files to the directory and there you go.

          <?php
          /*Simple thumbnail gallery by Bret Lanius 		 
          Some code from other sources								http://Bretlanius.com
          */
          function directory($dir,$filters){
          	$handle=opendir($dir);
          	$files=array();
          	if ($filters == "all"){
                  while(($file = readdir($handle))!==false){$files[] = $file;}}
          	if ($filters != "all"){
          		$filters=explode(",",$filters);
          		while (($file = readdir($handle))!==false) {
          			for ($f=0;$f<sizeof($filters);$f++):
          				$system=explode(".",$file);
          				if ($system[1] == $filters[$f]){$files[] = $file;}
          			endfor;
          		}
          	}
          	closedir($handle);
          	return $files;
          	}
          
          
          if ($Submit){
          $picsize=$select;
          }
          if (!$picsize){$piczie=40;}
          $files=directory(".","jpg,JPG");
          foreach ($files as $pic){?>
          		<A href=# Onclick=imgWindow("<?php echo "showpicture.php?pic=".$pic; ?>",450,400)>
          		<img src="gd.php?img_name=<?php echo $pic ?>&csize=<?php echo $picsize ?>" border="0" align="top"></a>
          <?php
          	}
          
          ?>
          

          The gd.php just resizes pictures and returns a graphic. I forget where this code came from but I use it a bit.

          <?
          	//usage gd.php?img_name=img.jpg&picsize=width
          	//Default width is 123
              /* Informs the browser the data being sent back is a Jpeg Image */
              Header ("Content-type: image/jpeg");
              /* loads image passed thru script
              ie: gd.php?img_name=zoom.jpg */
              $src_img = imagecreatefromjpeg($img_name);
              /* desired width of the thumbnail */
              if (!$picsize)
              	{$picsize = 123;
              	}
              /* grabs the height and width */
              $new_w = imagesx($src_img);
              $new_h = imagesy($src_img);
              /* calculates aspect ratio */
              $aspect_ratio = $new_h / $new_w;
              /* sets new size */
              $new_w = $picsize;
              $new_h = abs($new_w * $aspect_ratio);
              /* creates new image of that size */
              $dst_img = imagecreate($new_w,$new_h);
              /* copies resized portion of original image into new image */
              imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
              /* return jpeg data back to browser
                  include a second parameter of a file name if
                  you just want to save the new file to disk*/
              imagejpeg($dst_img);
              ?>
          

          In the header I have a javascript window opener function of:

          function imgWindow(url,w,h)
          {
          
          var the_features="width="+ w + " ,height=" +h+ " scrollbars";
           the_window=window.open(url,'MAPS',the_features);
           	var height=window.screen.availHeight;
          	var width=window.screen.availWidth;
          	//Calc left
          	var left_point=parseInt(width/2)-parseInt(w/2);
          	//Calc top
          	var top_point=parseInt(height/2)-parseInt(h/2);
          	the_window.moveTo(left_point, top_point);
          	//Show me -->
          	}
          	</script>
          

          Then in the popup window I have a hybrid PHP/Javascript code

          img src="<?php echo $pic;?>" name="theimage" onload="var Iwidth=window.document.theimage.width+40;
              var Iheight=window.document.theimage.height+100;
              var  height=window.screen.availHeight;
          	var  width =window.screen.availWidth;
          	var left_point=parseInt(width /2) - parseInt(Iwidth/2);
          	var top_point=parseInt(height/2)-parseInt(Iheight/2);
           self.resizeTo(Iwidth,Iheight);
           self.resizeTo(Iwidth,Iheight);
           self.focus();
           self.moveTo(left_point,top_point);"><br>
          
          <script language="JavaScript">window.document.write(window.document.theimage.src);</script>
          
            Write a Reply...