I have a PHP script that loads all images in a hard coded folder into JavaScript array:
<?
//PHP SCRIPT: readphp.php
Header("content-type: application/x-javascript");
//This function gets the file names of all images in the current directory
//and ouputs them as a JavaScript array
function returnimages($dirname=".") {
$pattern="/^.*\.(jpg|jpeg|png|gif)$/i"; //valid image extensions
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(preg_match($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'galleryarray['.$curimage.']="'.$file .'";';
$curimage++;
}
}
closedir($handle);
}
return($files);
}
echo 'var galleryarray=new Array();'; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names
?>
I call this script in an HTML file like this:
<script src="readphp.php"></script>
Then I use galleryarray
in other <script>
.
Now I want to expand my application with the following logic:
User will pass (never mind the details) a folder path. Then the path is passed to the PHP script which will load all images in that folder. I do something with these images and then the user will be asked to supply another folder path and so on and so forth.
How can I do that?