2) { foreach ($files1 as $file ) { $x = pathinfo($file)['extension']; if($file === '.' || $file === '..') {continue;} if ($x == 'mp4' || $x == 'jpg' || $x == 'jpeg' || $x == 'pdf') { array_push($filearray, "http://$hostpath/$imgpath$file"); } } $json = json_encode($filearray); echo $json; // var_dump($json); }