This line:
$echo "$files['$cnt']<br>";
has a dollar sign in front of "echo". Also, if there's less than forty files, you're going to run out of indexes in the array.
Try something like this instead:
$path = "fest";
$files = array();
$dir_handle = opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle))
$files[] = $file;
$amount = count($files);
echo "Number of files: $amount<br>";
if ($amount < 40)
$max = $amount;
else
$max = 40;
echo "hello<br>";
for ($cnt = 0; $cnt < $max; $cnt++)
echo $files[$cnt], '<br>';
?>