3v4l.org

run code in 300+ PHP versions simultaneously
<?php function genRandomString() { $length = 10; $characters = "0123456789abcdefghijklmnopqrstuvwxyz"; $string = ""; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters)-1)]; } return $string; } function makeRandomPath($dir, $ext) { do { $path = $dir."/".genRandomString().".".$ext; } while(file_exists($path)); return $path; } function makeRandomPathFromFilename($dir, $fn) { $ext = pathinfo($fn, PATHINFO_EXTENSION); return makeRandomPath($dir, $ext); } if(array_key_exists("filename", $_POST)) { $target_path = makeRandomPathFromFilename("upload", $_POST["filename"]); if(filesize($_FILES['uploadedfile']['tmp_name']) > 1000) { echo "File is too big"; } else if (! exif_imagetype($_FILES['uploadedfile']['tmp_name'])) { echo "File is not an image"; } else { if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file <a href=\"$target_path\">$target_path</a> has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } } } else { ?> <form enctype="multipart/form-data" action="index.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="1000" /> <input type="hidden" name="filename" value="<? print genRandomString(); ?>.jpg" /> Choose a JPEG to upload (max 1KB):<br/> <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> <?php } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 48
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 46
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3GS7Z
function name:  (null)
number of ops:  54
compiled vars:  !0 = $target_path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_R                      global              ~1      '_POST'
          1        ARRAY_KEY_EXISTS                                         'filename', ~1
          2      > JMPZ                                                     ~2, ->48
   28     3    >   INIT_FCALL                                               'makerandompathfromfilename'
          4        SEND_VAL                                                 'upload'
          5        FETCH_R                      global              ~3      '_POST'
          6        FETCH_DIM_R                                      ~4      ~3, 'filename'
          7        SEND_VAL                                                 ~4
          8        DO_FCALL                                      0  $5      
          9        ASSIGN                                                   !0, $5
   31    10        INIT_FCALL                                               'filesize'
         11        FETCH_R                      global              ~7      '_FILES'
         12        FETCH_DIM_R                                      ~8      ~7, 'uploadedfile'
         13        FETCH_DIM_R                                      ~9      ~8, 'tmp_name'
         14        SEND_VAL                                                 ~9
         15        DO_ICALL                                         $10     
         16        IS_SMALLER                                               1000, $10
         17      > JMPZ                                                     ~11, ->20
   32    18    >   ECHO                                                     'File+is+too+big'
         19      > JMP                                                      ->47
   33    20    >   INIT_FCALL_BY_NAME                                       'exif_imagetype'
         21        CHECK_FUNC_ARG                                           
         22        FETCH_FUNC_ARG               global              $12     '_FILES'
         23        FETCH_DIM_FUNC_ARG                               $13     $12, 'uploadedfile'
         24        FETCH_DIM_FUNC_ARG                               $14     $13, 'tmp_name'
         25        SEND_FUNC_ARG                                            $14
         26        DO_FCALL                                      0  $15     
         27        BOOL_NOT                                         ~16     $15
         28      > JMPZ                                                     ~16, ->31
   34    29    >   ECHO                                                     'File+is+not+an+image'
         30      > JMP                                                      ->47
   36    31    >   INIT_FCALL                                               'move_uploaded_file'
         32        FETCH_R                      global              ~17     '_FILES'
         33        FETCH_DIM_R                                      ~18     ~17, 'uploadedfile'
         34        FETCH_DIM_R                                      ~19     ~18, 'tmp_name'
         35        SEND_VAL                                                 ~19
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $20     
         38      > JMPZ                                                     $20, ->46
   37    39    >   ROPE_INIT                                     5  ~22     'The+file+%3Ca+href%3D%22'
         40        ROPE_ADD                                      1  ~22     ~22, !0
         41        ROPE_ADD                                      2  ~22     ~22, '%22%3E'
         42        ROPE_ADD                                      3  ~22     ~22, !0
         43        ROPE_END                                      4  ~21     ~22, '%3C%2Fa%3E+has+been+uploaded'
         44        ECHO                                                     ~21
         45      > JMP                                                      ->47
   39    46    >   ECHO                                                     'There+was+an+error+uploading+the+file%2C+please+try+again%21'
         47    > > JMP                                                      ->53
   44    48    >   ECHO                                                     '%0A%3Cform+enctype%3D%22multipart%2Fform-data%22+action%3D%22index.php%22+method%3D%22POST%22%3E%0A%3Cinput+type%3D%22hidden%22+name%3D%22MAX_FILE_SIZE%22+value%3D%221000%22+%2F%3E%0A%3Cinput+type%3D%22hidden%22+name%3D%22filename%22+value%3D%22'
   47    49        INIT_FCALL                                               'genrandomstring'
         50        DO_FCALL                                      0  $25     
         51        ECHO                                                     $25
         52        ECHO                                                     '.jpg%22+%2F%3E%0AChoose+a+JPEG+to+upload+%28max+1KB%29%3A%3Cbr%2F%3E%0A%3Cinput+name%3D%22uploadedfile%22+type%3D%22file%22+%2F%3E%3Cbr+%2F%3E%0A%3Cinput+type%3D%22submit%22+value%3D%22Upload+File%22+%2F%3E%0A%3C%2Fform%3E%0A'
   52    53    > > RETURN                                                   1

Function genrandomstring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 5
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 5
Branch analysis from position: 16
Branch analysis from position: 5
filename:       /in/3GS7Z
function name:  genRandomString
number of ops:  18
compiled vars:  !0 = $length, !1 = $characters, !2 = $string, !3 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 10
    5     1        ASSIGN                                                   !1, '0123456789abcdefghijklmnopqrstuvwxyz'
    6     2        ASSIGN                                                   !2, ''
    8     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->14
    9     5    >   INIT_FCALL                                               'mt_rand'
          6        SEND_VAL                                                 0
          7        STRLEN                                           ~8      !1
          8        SUB                                              ~9      ~8, 1
          9        SEND_VAL                                                 ~9
         10        DO_ICALL                                         $10     
         11        FETCH_DIM_R                                      ~11     !1, $10
         12        ASSIGN_OP                                     8          !2, ~11
    8    13        PRE_INC                                                  !3
         14    >   IS_SMALLER                                               !3, !0
         15      > JMPNZ                                                    ~14, ->5
   12    16    > > RETURN                                                   !2
   13    17*     > RETURN                                                   null

End of function genrandomstring

Function makerandompath:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
filename:       /in/3GS7Z
function name:  makeRandomPath
number of ops:  15
compiled vars:  !0 = $dir, !1 = $ext, !2 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2    >   CONCAT                                           ~3      !0, '%2F'
          3        INIT_FCALL                                               'genrandomstring'
          4        DO_FCALL                                      0  $4      
          5        CONCAT                                           ~5      ~3, $4
          6        CONCAT                                           ~6      ~5, '.'
          7        CONCAT                                           ~7      ~6, !1
          8        ASSIGN                                                   !2, ~7
   18     9        INIT_FCALL                                               'file_exists'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $9      
         12      > JMPNZ                                                    $9, ->2
   19    13    > > RETURN                                                   !2
   20    14*     > RETURN                                                   null

End of function makerandompath

Function makerandompathfromfilename:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3GS7Z
function name:  makeRandomPathFromFilename
number of ops:  13
compiled vars:  !0 = $dir, !1 = $fn, !2 = $ext
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2        INIT_FCALL                                               'pathinfo'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 4
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !2, $3
   24     7        INIT_FCALL                                               'makerandompath'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !2
         10        DO_FCALL                                      0  $5      
         11      > RETURN                                                   $5
   25    12*     > RETURN                                                   null

End of function makerandompathfromfilename

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.4 ms | 1407 KiB | 27 Q