3v4l.org

run code in 300+ PHP versions simultaneously
<?php // mock $_GET['f'] = 'imagenes'; $_GET['folder'] = 'foods'; $_GET['type'] = 'salads'; $_GET['desc'] = 'green'; $_GET['dim'] = '50'; $_GET['id'] = '23'; // define expected $params = ['f', 'folder', 'type', 'desc', 'dim', 'id']; // loop over and output: /imagenes/foods/salads/green_50/23.png $path = null; foreach ($params as $key => $param) { if (isset($_GET[$param])) { $path .= ($param == 'dim' ? '_' : '/').basename($_GET[$param]); unset($params[$key]); } } $path .= '.png'; echo $path; __halt_compiler(); // check all params were passed if (!empty($params)) { die('Invalid request'); } // check file exists if (!file_exists($path)) { die('File does not exist'); } // check file is image if (!getimagesize($path)) { die('Invalid image'); } // all good serve file header("Content-Type: image/png"); header('Content-Length: '.filesize($path)); readfile($path);

preferences:
64.27 ms | 402 KiB | 5 Q