Not sure. you might want to put some else statements in there, so that if the routine fails, you know where it fails.
Furthermore this:
$getRand = mt_rand(1, count($files));
for($i = 0 ; $i < count($files) ; $i++) {
$file2 = $files[$getRand];
}
Does not really make sense. Why the for loop? I presume it returns 1 file?