Jump to content

[SOLVED] Get All Images In Folder Automatically


refiking

Recommended Posts

How can I take alter this code to retrieve all the images from the images/header folder instead of having to list each one separately?

 

<script language="JavaScript">

// configuration structure
var A_TPL = {
	// randomize the array each time page loads
	'random' : true,
	// number of transparency changes during the transition
	//	increase for smoother transition, reduce for less CPU usage
	'steps' : 20,
	// transition duration in seconds
	'transtime': .5,
	// slide time in seconds
	'slidetime': 5,
	// width of the slide (optional)
	'width' : 200,
	// height of the slide (optional)
	'height': 200,
	// alt text for the image (optional)
	'alt' : '',
	// css class assigned to the slide <img> (optional)
	'css' : ''
};

// list of images to display
var A_ITEMS = [
	'images/masthead.jpg',
	'images/header/1.jpg',
	'images/header/2.jpg'
];

// fader initialization	
var mySlideShow = new tFader (A_ITEMS, A_TPL);

</script>

Link to comment
Share on other sites

You could use php to read the files in a folder and output an array of all images in js format. Javascript can't read what files are in a folder.

example

<script>
var jsimages=new Array();
<?php
$files=array();
//your read directory script here
foreach($files as $file){
  //add image urls to the js array
  echo "jsimages.push('{$file}')\n" ;
}
?>
</script>

Link to comment
Share on other sites

Keep in mind that the read dir script isnt written in my example

however a script to read a folder with images is prob written over a thousand times on this forum I doubt you will have any trouble finding that.

As for the array look at the following in your script.

// list of images to display
   var A_ITEMS = [
      'images/masthead.jpg',
      'images/header/1.jpg',
      'images/header/2.jpg'
   ];

that's a js array.

so A_ITEMS is the array name.

Rename jsimages to A_ITEMS and it might work(assuming the php array has the image urls in it).

Link to comment
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.