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));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
2 jumps found. (Code = 47) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
2 jumps found. (Code = 47) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 40
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 68
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
Branch analysis from position: 40
Branch analysis from position: 32
Branch analysis from position: 28
Branch analysis from position: 23
Branch analysis from position: 18
filename:       /in/jHkSU
function name:  (null)
number of ops:  75
compiled vars:  !0 = $filename, !1 = $image
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'TOKEN'
          2        SEND_VAL                                                 '%3Csecure_token%3E'
          3        DO_ICALL                                                 
   13     4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'UPLOADS'
          6        SEND_VAL                                                 '%2Fin%2Fuploads%2F'
          7        DO_ICALL                                                 
   14     8        INIT_FCALL                                               'define'
          9        SEND_VAL                                                 'URL'
         10        SEND_VAL                                                 'http%3A%2F%2Fwww.example.com%2Fuploads%2F'
         11        DO_ICALL                                                 
   23    12        ISSET_ISEMPTY_VAR                             3  ~5      '_POST'
         13      > JMPNZ_EX                                         ~5      ~5, ->18
         14    >   FETCH_IS                                         ~6      '_POST'
         15        ISSET_ISEMPTY_DIM_OBJ                         0  ~7      ~6, 'image'
         16        BOOL_NOT                                         ~8      ~7
         17        BOOL                                             ~5      ~8
         18    > > JMPNZ_EX                                         ~5      ~5, ->23
         19    >   FETCH_IS                                         ~9      '_POST'
         20        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     ~9, 'token'
         21        BOOL_NOT                                         ~11     ~10
         22        BOOL                                             ~5      ~11
         23    > > JMPNZ_EX                                         ~5      ~5, ->28
         24    >   FETCH_IS                                         ~12     '_POST'
         25        ISSET_ISEMPTY_DIM_OBJ                         0  ~13     ~12, 'name'
         26        BOOL_NOT                                         ~14     ~13
         27        BOOL                                             ~5      ~14
         28    > > JMPZ                                                     ~5, ->32
   24    29    >   INIT_FCALL                                               'output'
         30        SEND_VAL                                                 <array>
         31        DO_FCALL                                      0          
   28    32    >   FETCH_R                      global              ~16     '_POST'
         33        FETCH_DIM_R                                      ~17     ~16, 'token'
         34        FETCH_CONSTANT                                   ~18     'TOKEN'
         35        IS_NOT_IDENTICAL                                         ~17, ~18
         36      > JMPZ                                                     ~19, ->40
   29    37    >   INIT_FCALL                                               'output'
         38        SEND_VAL                                                 <array>
         39        DO_FCALL                                      0          
   33    40    >   INIT_FCALL                                               'trim'
         41        INIT_FCALL                                               'preg_replace'
         42        SEND_VAL                                                 '%2F%5B%5E%5Cd%5Cw.%5D%2B%2Fi'
         43        SEND_VAL                                                 ''
         44        FETCH_R                      global              ~21     '_POST'
         45        FETCH_DIM_R                                      ~22     ~21, 'name'
         46        SEND_VAL                                                 ~22
         47        DO_ICALL                                         $23     
         48        SEND_VAR                                                 $23
         49        DO_ICALL                                         $24     
         50        ASSIGN                                                   !0, $24
   34    51        INIT_FCALL                                               'base64_decode'
         52        FETCH_R                      global              ~26     '_POST'
         53        FETCH_DIM_R                                      ~27     ~26, 'image'
         54        SEND_VAL                                                 ~27
         55        DO_ICALL                                         $28     
         56        ASSIGN                                                   !1, $28
   37    57        INIT_FCALL                                               'file_put_contents'
         58        FETCH_CONSTANT                                   ~30     'UPLOADS'
         59        CONCAT                                           ~31     ~30, !0
         60        SEND_VAL                                                 ~31
         61        SEND_VAR                                                 !1
         62        DO_ICALL                                         $32     
         63        BOOL_NOT                                         ~33     $32
         64      > JMPZ                                                     ~33, ->68
   38    65    >   INIT_FCALL                                               'output'
         66        SEND_VAL                                                 <array>
         67        DO_FCALL                                      0          
   42    68    >   INIT_FCALL                                               'output'
         69        FETCH_CONSTANT                                   ~35     'URL'
         70        CONCAT                                           ~36     ~35, !0
         71        INIT_ARRAY                                       ~37     ~36, 'href'
         72        SEND_VAL                                                 ~37
         73        DO_FCALL                                      0          
         74      > RETURN                                                   1

Function output:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/jHkSU
function name:  output
number of ops:  10
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV_INIT                                        !0      <array>
   17     1        INIT_FCALL                                               'header'
          2        SEND_VAL                                                 'Content-Type%3A+application%2Fjson'
          3        DO_ICALL                                                 
   18     4        INIT_FCALL                                               'json_encode'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        ECHO                                                     $2
   19     8      > EXIT                                                     
   20     9*     > RETURN                                                   null

End of function output

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.16 ms | 1407 KiB | 31 Q