3v4l.org

run code in 300+ PHP versions simultaneously
<?php foreach ($_FILES as $file) { // array of valid extensions $validExtensions = array('.jpg', '.jpeg', '.gif', '.png'); // get extension of the uploaded file $fileExtension = strrchr($file['name'], "."); // check if file Extension is on the list of allowed ones if (in_array($fileExtension, $validExtensions)) { $newNamePrefix = time() . '_'; save('uploads/' . $newNamePrefix . $file['name']); echo 'Done ...'; } else { echo 'You must upload an image...'; } } ?>
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.25, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0

preferences:
172.23 ms | 404 KiB | 216 Q