3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Simple file uplaod script. * NO WARRANTY. THIS SCRIPT IS ONLY AN EXAMPLE. * INPUT VALIDATION IS MINIMAL. DO NOT USE IN PRODUCTION * * @copyright 2014 Alex Soban * @license http://opensource.org/licenses/MIT * @author Alex Soban <me@soban.co> */ define('TOKEN', '<secure_token>'); define('UPLOADS', __DIR__ . '/uploads/'); define('URL', 'http://www.example.com/uploads/'); function output(array $data = array()) { header('Content-Type: application/json'); echo json_encode($data); exit; } // `name` check is optional if (empty($_POST) || !isset($_POST['image'] || !isset($_POST['token'] || !isset($_POST['name'])) { output(array('error' => 'Invalid input.')); } // `token` verification if ($_POST['token'] !== TOKEN) { output(array('error' => 'Invalid token.')); } // get the filename and contents $filename = trim(preg_replace('/[^\d\w.]+/i', '', $_POST['name'])); $image = base64_decode($_POST['image']); // "upload" the file to our uploads directory if (!file_put_contents(UPLOADS . $filename, $image)) { output(array('error' => 'Failed saving file.')); } // return file public URL output(array('href' => URL . $filename));
Output for 5.4.0 - 5.4.28
Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR), expecting ',' or ')' in /in/ACTop on line 23
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_BOOLEAN_OR, expecting ',' or ')' in /in/ACTop on line 23
Process exited with code 255.

preferences:
179.18 ms | 1386 KiB | 65 Q