Código PHP:
<?php
$dir = "images/";
$c1 = count($files);
$i=0;
?>
<script>
var images = [<? if (is_dir($dir)){if ($dh = opendir($dir)){while (($file = readdir($dh)) !== false){if($file != '.' && $file != '..' && $file != 'Thumbs.db'){if($i==0){$firstpic=$file;}$i++;$filenames.="'".$file."', ";}}echo substr($filenames, 0, -2);closedir($dh);}}?>];