JS:
<script>
function loadPHP()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","somephp.php",true); //replace this with your file name
xmlhttp.send();
}
</script>
HTML:
<button onclick="loadPHP()">Click to load php</button>
<div id="myDiv"></div>
PHP:
<?php
$dir = "img";
if (is_dir($dir)){
if ($dh = opendir($dir)){
$images = array();
while (($file = readdir($dh)) !== false){
if (!is_dir($dir.$file)) $images[] = $file;
}
closedir($dh);
}
}
$max = count($images);
$toprint = "<ul>";
foreach($images as $x => $y){
$toprint .= ("<li>".$y."<br /></li>");
}
echo $toprint;
?>