3v4l.org

run code in 300+ PHP versions simultaneously
<!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 7.4.26 - 7.4.32, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
<!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> Warning: file_exists(): open_basedir restriction in effect. File(./picture) is not within the allowed path(s): (/tmp:/in:/etc) in /in/Gjqpe on line 30 ERROR: Directory doesnot exists.
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.25, 7.4.33, 8.0.0 - 8.0.13
<!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.

preferences:
296.06 ms | 406 KiB | 469 Q