3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<!doctype html> <head> <title>Creating an image gallery</title> <style type="text/css"> ul { list-style-type: none; } li { float: left; padding:10px; margin:10px; font:bold 10px Verdana sans-serief; } img { display:block; border:1px solid #333300; margin-border:5px; } </style> </head> <body> <h2>Creating an image gallery</h2> <ul> <?php $photosDir='./picture'; $photosExt=array('gif', 'jpg','jpeg','tif', 'tiff', 'bmp','png'); $photosList=array(); if(file_exists($photosDir)) { $dp=opendir($photosDir) or die ('ERROR: Cannot open Directory'); while($file=readdir($dp)) { if($file!='.' && $file!='..') { $fileData=pathinfo($file); if(in_array($fileData['extension'],$photosExt)) { $photosList[]="$photosDir/$file"; } } } closedir($dp); } else { die('ERROR: Directory doesnot exists.'); } if(count($photosList)>0) { for($x=0; $x<count($photosList); $x++) ?> <li> <img height="150" width="200" src="<?php echo $photosList[$x];?>"/> <?php echo basename($photosList[$x]);?><br/> <?php echo round(filesize($photosList[$x])/1024) . 'KB' ;?> </li> <?php } else { die('ERROR: No image found in Directory.'); } ?> </ul> </body> </html>
Output for 4.3.0 - 7.2.0
<!doctype html> <head> <title>Creating an image gallery</title> <style type="text/css"> ul { list-style-type: none; } li { float: left; padding:10px; margin:10px; font:bold 10px Verdana sans-serief; } img { display:block; border:1px solid #333300; margin-border:5px; } </style> </head> <body> <h2>Creating an image gallery</h2> <ul> ERROR: Directory doesnot exists.