I have two forms in two different divs and in one of which I am trying to render the images from a folder:
First form renders a ul li and its id and name is matchListUL.
echo '<li id="matchList" name="matchList"><a href="'.implode('; ', $data).'">'.implode('; ', $data).'</a></li>';
Through a javascript I am passing the value of selected li to a php file named loadimages.php. The following is the javascript.
<script>
$(document).ready(function(){
$('ul#matchListUL li a').click(function(){
var match = $(this).attr('href');
if (match !== null && match !=="") {
$.post("loadimages.php", { match : match }, function(output){
$("#imageload").html(output).show();
});
return false;
})
})
</script>
The second div has id and name as imageload. The loadimages.php is as follows:
$match = $_POST['match'];
$selectedDir = $_SESSION['seldir'];
$tarDir = "kennels/" . $selectedDir . "/" . $match;
$my_image_array = scandir($tarDir);
$img_string = "";
foreach($my_image_array as $img_name){
if(strlen($img_name) > 2 ) {
$imgname = $tarDir . $img_name;
$img_string .= '<img src = "' .$imgname. '">';
}
}
echo $img_string;
When I run the code from loadimages.php, the images are not getting rendered. Do I have to change this line in my javascript to suit image rendering?
$("#imageload").html(output).show();
The same code when I run (with minimal modifications) from my main index.php, it renders images.
I tried an alternative to the code i have in loadimages.php where I hardcoded the path to the images folder:
$files = glob("kennels/projects/images/*.jpg");
for ($i=1; $i<count($files); $i++)
{
$num = $files[$i];
echo '<img src="'.$num.'" id="thumbNails"/>';
}
This too works perfectly from my index.php, while not rendering any images from loadimages.php.