Dynamically select images for slide show using javascript


I am using the following code to select images dynamically from a folder then display them in slide show.. but this code selects only first image... please guide me where is the error...

PHP file is: named: test.php

<?php header("content-type: application/x-javascript"); function returnimages($dirname=".") { $files = array(); $curimage = 0; //valid image extensions $pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)"; if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))) { if(eregi($pattern, $file)){ echo 'galleryarray[' . $curimage . '] = "' . $file . '";'; $curimage++; } } closedir($handle); } return($files); } //Define array in JavaScript returnimages() //Output the array elements containing the image file names echo 'var galleryarray = new Array();'; ?>

Html code is:

<html> <head> <title></title> <script src="test.php"></script> <script type="text/javascript"> var galleryarray = returnimages(); var curimg = 0; function rotateimages(){ // var imagesDirectory = "pics/" + galleryarray[curimg]; var imagesDirectory =galleryarray[curimg]; document.getElementById("slideshow").setAttribute("src", imagesDirectory) curimg = (curimg < galleryarray.length - 1) ? curimg + 1 : 0 } window.onload = function(){ setInterval("rotateimages()", 2500) } </script> </head> <body> <img width="468" height="312" id="slideshow" src="Slide1.jpg"> </body> </html>


You're actually trying to call a php function returnimages() by javaScript. That's not possible anyway.


  • Execute a piece of code from the data-section
  • Google App Indexing not resolving for Swift?
  • getting empty value in viewWillAppear( ) but getting valid value in viewDidLoad( )
  • Printing input from TextField to a Label in Xcode with Swift
  • Error binding to target method
  • Custom font for MKAnnotationView Callout
  • Reusing try catch for wcf call
  • Decoding PubNub messages with golang JSON
  • How to access UIViewController's varaibles inside “func applicationWillResignActive”? Swift, iO
  • python cdll can't find module
  • Auto Height of UICollectionView inside UITableViewCell
  • Convert Func to Func
  • Getting directory of input file (Applescript)
  • Is it possible to make imports depend on the location of my Lua script instead of the current direct
  • Custom Nav Title offset ios 11
  • removing last 3 characters on a file (file extension)
  • Symfony 2. CSRF token is invalid
  • Unable to decode certificate at client new X509Certificate2()
  • Functions in global context
  • Update CALayer sublayers immediately
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Updating server-side rendering client-side
  • Sending data from AppleScript to FileMaker records
  • Release, debug version and Authorization Google?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Is there a mandatory requirement to switch app.yaml?
  • How to include full .NET prerequisite for Wix Burn installer
  • Benchmarking RAM performance - UWP and C#
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How to set the response of a form post action to a iframe source?
  • Angular 2 constructor injection vs direct access
  • How do I configure my settings file to work with unit tests?
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Is it possible to post an object from jquery to bottle.py?
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Busy indicator not showing up in wpf window [duplicate]
  • Binding checkboxes to object values in AngularJs