PHP menampilkan gambar dalam folder

PHP (gallery.php)

<table cellspacing="2" cellpadding="5">
<tr>
<?php
$folder = "./images/";
$handle = opendir($folder);
$i = 1;
$fileGambar = array('png', 'jpg', 'jpeg', 'gif');
while(false !== ($file = readdir($handle))){
    $fileAndExt = explode('.', $file);
    if(in_array(end($fileAndExt), $fileGambar)){
        echo '<td style="border:1px solid #000000;" align="center">
<img src="'.$folder.''.$file.'" width="100" /><br />'.$file.'
        </td>';

        if(($i % 4) == 0){
            echo '</tr><tr>';
        }
        $i++;
    }
}
?>
</tr>
</table>

Jquery ajax post variable

HTML (ajax.html)

<html>
<head>
<title>Jquery ajax</title>
</head>
<script src="http://code.jquery.com/jquery-1.3.2.min.js"></script>
<script>
function dojqueryajax(coba){
$.post('ajax.php', {coba:coba}, function (data){
$('#hasil').text(data);
});
}
</script>
<body>
<a href="javascript:;" onclick="dojqueryajax('berhasil');">coba</a>
<div id="hasil"></div>
</body>
</html>


PHP (ajax.php)

<?php
 echo $_POST['coba'];
?>