3v4l.org

run code in 300+ PHP versions simultaneously
<?php $parent_directory = './Videos'; $file_types = 'jpg,png,gif,tif'; //===================================================// // FUNCTION: directoryToArray // // // // Parameters: // // - $root: The directory to process // // - $to_return: f=files, d=directories, b=both // // - $file_types: the extensions of file types to // // to return if files selected // //===================================================// function directoryToArray($root, $to_return='b', $file_types=false) { $array_items = array(); if ($file_types) { $file_types=explode(',',$file_types); } if ($handle = opendir($root)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $add_item = false; $type = (is_dir($root. "/" . $file))?'d':'f'; $name = preg_replace("/\/\//si", "/", $file); if ($type=='d' && ($to_return=='b' || $to_return=='d') ) { $add_item = true; } if ($type=='f' && ($to_return=='b' || $to_return=='f') ) { $ext = end(explode('.',$name)); if ( !$file_types || in_array($ext, $file_types) ) { $add_item = true; } } if ($add_item) { $array_items[] = array ( 'name'=>$name, 'type'=>$type, 'root'=>$root); } } } // End While closedir($handle); } // End If return $array_items; } if (isset($_POST[pickfile])) { // User has selected a file take whatever action you want based // upon the values for folder and file } else { echo "<form name=\"pickFile\" method=\"POST\">\n"; $directoryList = directoryToArray($parent_directory,'d'); echo "<select name=\"folder\" onchange=\"changeFolder(this.value);\">\n"; foreach ($directoryList as $folder) { $selected = ($_POST[folder]==$folder[name])? 'selected' : ''; echo "<option value=\"$folder[name]\" $selected>$folder[name]</option>\n"; } echo '</select><br><br>'; $working_folder = ($_POST[folder]) ? $_POST[folder] : $directoryList[0][name]; $fileList = directoryToArray($parent_directory.'/'.$working_folder,'f',$file_types); echo "<select name=\"file\">\n"; foreach ($fileList as $file) { echo "<option value=\"$file[name]\">$file[name]</option>\n"; } echo '</select><br><br>'; echo "<button type=\"submit\" name=\"pickfile\">Submit</button>\n"; } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 38
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 38
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 49
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 77) Position 1 = 64, Position 2 = 74
Branch analysis from position: 64
2 jumps found. (Code = 78) Position 1 = 65, Position 2 = 74
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
Branch analysis from position: 49
2 jumps found. (Code = 77) Position 1 = 64, Position 2 = 74
Branch analysis from position: 64
Branch analysis from position: 74
Branch analysis from position: 38
filename:       /in/5uRVR
function name:  (null)
number of ops:  78
compiled vars:  !0 = $parent_directory, !1 = $file_types, !2 = $directoryList, !3 = $folder, !4 = $selected, !5 = $working_folder, !6 = $fileList, !7 = $file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '.%2FVideos'
    4     1        ASSIGN                                                   !1, 'jpg%2Cpng%2Cgif%2Ctif'
   49     2        FETCH_CONSTANT                                   ~11     'pickfile'
          3        FETCH_IS                                         ~10     '_POST'
          4        ISSET_ISEMPTY_DIM_OBJ                         0          ~10, ~11
          5      > JMPZ                                                     ~12, ->7
          6    > > JMP                                                      ->77
   59     7    >   ECHO                                                     '%3Cform+name%3D%22pickFile%22+method%3D%22POST%22%3E%0A'
   61     8        INIT_FCALL                                               'directorytoarray'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 'd'
         11        DO_FCALL                                      0  $13     
         12        ASSIGN                                                   !2, $13
   63    13        ECHO                                                     '%3Cselect+name%3D%22folder%22+onchange%3D%22changeFolder%28this.value%29%3B%22%3E%0A'
   64    14      > FE_RESET_R                                       $15     !2, ->38
         15    > > FE_FETCH_R                                               $15, !3, ->38
   65    16    >   FETCH_CONSTANT                                   ~17     'folder'
         17        FETCH_R                      global              ~16     '_POST'
         18        FETCH_DIM_R                                      ~18     ~16, ~17
         19        FETCH_CONSTANT                                   ~19     'name'
         20        FETCH_DIM_R                                      ~20     !3, ~19
         21        IS_EQUAL                                                 ~18, ~20
         22      > JMPZ                                                     ~21, ->25
         23    >   QM_ASSIGN                                        ~22     'selected'
         24      > JMP                                                      ->26
         25    >   QM_ASSIGN                                        ~22     ''
         26    >   ASSIGN                                                   !4, ~22
   66    27        ROPE_INIT                                     7  ~27     '%3Coption+value%3D%22'
         28        FETCH_DIM_R                                      ~24     !3, 'name'
         29        ROPE_ADD                                      1  ~27     ~27, ~24
         30        ROPE_ADD                                      2  ~27     ~27, '%22+'
         31        ROPE_ADD                                      3  ~27     ~27, !4
         32        ROPE_ADD                                      4  ~27     ~27, '%3E'
         33        FETCH_DIM_R                                      ~25     !3, 'name'
         34        ROPE_ADD                                      5  ~27     ~27, ~25
         35        ROPE_END                                      6  ~26     ~27, '%3C%2Foption%3E%0A'
         36        ECHO                                                     ~26
   64    37      > JMP                                                      ->15
         38    >   FE_FREE                                                  $15
   68    39        ECHO                                                     '%3C%2Fselect%3E%3Cbr%3E%3Cbr%3E'
   70    40        FETCH_CONSTANT                                   ~32     'folder'
         41        FETCH_R                      global              ~31     '_POST'
         42        FETCH_DIM_R                                      ~33     ~31, ~32
         43      > JMPZ                                                     ~33, ->49
         44    >   FETCH_CONSTANT                                   ~35     'folder'
         45        FETCH_R                      global              ~34     '_POST'
         46        FETCH_DIM_R                                      ~36     ~34, ~35
         47        QM_ASSIGN                                        ~37     ~36
         48      > JMP                                                      ->53
         49    >   FETCH_CONSTANT                                   ~39     'name'
         50        FETCH_DIM_R                                      ~38     !2, 0
         51        FETCH_DIM_R                                      ~40     ~38, ~39
         52        QM_ASSIGN                                        ~37     ~40
         53    >   ASSIGN                                                   !5, ~37
   72    54        INIT_FCALL                                               'directorytoarray'
         55        CONCAT                                           ~42     !0, '%2F'
         56        CONCAT                                           ~43     ~42, !5
         57        SEND_VAL                                                 ~43
         58        SEND_VAL                                                 'f'
         59        SEND_VAR                                                 !1
         60        DO_FCALL                                      0  $44     
         61        ASSIGN                                                   !6, $44
   74    62        ECHO                                                     '%3Cselect+name%3D%22file%22%3E%0A'
   75    63      > FE_RESET_R                                       $46     !6, ->74
         64    > > FE_FETCH_R                                               $46, !7, ->74
   76    65    >   ROPE_INIT                                     5  ~50     '%3Coption+value%3D%22'
         66        FETCH_DIM_R                                      ~47     !7, 'name'
         67        ROPE_ADD                                      1  ~50     ~50, ~47
         68        ROPE_ADD                                      2  ~50     ~50, '%22%3E'
         69        FETCH_DIM_R                                      ~48     !7, 'name'
         70        ROPE_ADD                                      3  ~50     ~50, ~48
         71        ROPE_END                                      4  ~49     ~50, '%3C%2Foption%3E%0A'
         72        ECHO                                                     ~49
   75    73      > JMP                                                      ->64
         74    >   FE_FREE                                                  $46
   78    75        ECHO                                                     '%3C%2Fselect%3E%3Cbr%3E%3Cbr%3E'
   80    76        ECHO                                                     '%3Cbutton+type%3D%22submit%22+name%3D%22pickfile%22%3ESubmit%3C%2Fbutton%3E%0A'
   84    77    > > RETURN                                                   1

Function directorytoarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 87
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 84, Position 2 = 16
Branch analysis from position: 84
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 78
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 45
Branch analysis from position: 40
2 jumps found. (Code = 47) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 47
Branch analysis from position: 46
2 jumps found. (Code = 46) Position 1 = 49, Position 2 = 54
Branch analysis from position: 49
2 jumps found. (Code = 47) Position 1 = 51, Position 2 = 53
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 72
Branch analysis from position: 55
2 jumps found. (Code = 47) Position 1 = 65, Position 2 = 70
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 72
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 78
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 84, Position 2 = 16
Branch analysis from position: 84
Branch analysis from position: 16
Branch analysis from position: 78
Branch analysis from position: 72
Branch analysis from position: 70
Branch analysis from position: 72
Branch analysis from position: 53
Branch analysis from position: 54
Branch analysis from position: 47
Branch analysis from position: 44
Branch analysis from position: 45
Branch analysis from position: 30
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 45
Branch analysis from position: 40
Branch analysis from position: 45
Branch analysis from position: 78
Branch analysis from position: 20
Branch analysis from position: 87
Branch analysis from position: 10
filename:       /in/5uRVR
function name:  directoryToArray
number of ops:  89
compiled vars:  !0 = $root, !1 = $to_return, !2 = $file_types, !3 = $array_items, !4 = $handle, !5 = $file, !6 = $add_item, !7 = $type, !8 = $name, !9 = $ext
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'b'
          2        RECV_INIT                                        !2      <false>
   16     3        ASSIGN                                                   !3, <array>
   17     4      > JMPZ                                                     !2, ->10
          5    >   INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '%2C'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $11     
          9        ASSIGN                                                   !2, $11
   18    10    >   INIT_FCALL                                               'opendir'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $13     
         13        ASSIGN                                           ~14     !4, $13
         14      > JMPZ                                                     ~14, ->87
   19    15    > > JMP                                                      ->78
   20    16    >   IS_NOT_EQUAL                                     ~15     !5, '.'
         17      > JMPZ_EX                                          ~15     ~15, ->20
         18    >   IS_NOT_EQUAL                                     ~16     !5, '..'
         19        BOOL                                             ~15     ~16
         20    > > JMPZ                                                     ~15, ->78
   22    21    >   ASSIGN                                                   !6, <false>
   23    22        INIT_FCALL                                               'is_dir'
         23        CONCAT                                           ~18     !0, '%2F'
         24        CONCAT                                           ~19     ~18, !5
         25        SEND_VAL                                                 ~19
         26        DO_ICALL                                         $20     
         27      > JMPZ                                                     $20, ->30
         28    >   QM_ASSIGN                                        ~21     'd'
         29      > JMP                                                      ->31
         30    >   QM_ASSIGN                                        ~21     'f'
         31    >   ASSIGN                                                   !7, ~21
   24    32        INIT_FCALL                                               'preg_replace'
         33        SEND_VAL                                                 '%2F%5C%2F%5C%2F%2Fsi'
         34        SEND_VAL                                                 '%2F'
         35        SEND_VAR                                                 !5
         36        DO_ICALL                                         $23     
         37        ASSIGN                                                   !8, $23
   26    38        IS_EQUAL                                         ~25     !7, 'd'
         39      > JMPZ_EX                                          ~25     ~25, ->45
         40    >   IS_EQUAL                                         ~26     !1, 'b'
         41      > JMPNZ_EX                                         ~26     ~26, ->44
         42    >   IS_EQUAL                                         ~27     !1, 'd'
         43        BOOL                                             ~26     ~27
         44    >   BOOL                                             ~25     ~26
         45    > > JMPZ                                                     ~25, ->47
   27    46    >   ASSIGN                                                   !6, <true>
   30    47    >   IS_EQUAL                                         ~29     !7, 'f'
         48      > JMPZ_EX                                          ~29     ~29, ->54
         49    >   IS_EQUAL                                         ~30     !1, 'b'
         50      > JMPNZ_EX                                         ~30     ~30, ->53
         51    >   IS_EQUAL                                         ~31     !1, 'f'
         52        BOOL                                             ~30     ~31
         53    >   BOOL                                             ~29     ~30
         54    > > JMPZ                                                     ~29, ->72
   31    55    >   INIT_FCALL                                               'end'
         56        INIT_FCALL                                               'explode'
         57        SEND_VAL                                                 '.'
         58        SEND_VAR                                                 !8
         59        DO_ICALL                                         $32     
         60        SEND_VAR_NO_REF                               0          $32
         61        DO_ICALL                                         $33     
         62        ASSIGN                                                   !9, $33
   32    63        BOOL_NOT                                         ~35     !2
         64      > JMPNZ_EX                                         ~35     ~35, ->70
         65    >   INIT_FCALL                                               'in_array'
         66        SEND_VAR                                                 !9
         67        SEND_VAR                                                 !2
         68        DO_ICALL                                         $36     
         69        BOOL                                             ~35     $36
         70    > > JMPZ                                                     ~35, ->72
   33    71    >   ASSIGN                                                   !6, <true>
   37    72    > > JMPZ                                                     !6, ->78
   38    73    >   INIT_ARRAY                                       ~39     !8, 'name'
         74        ADD_ARRAY_ELEMENT                                ~39     !7, 'type'
         75        ADD_ARRAY_ELEMENT                                ~39     !0, 'root'
         76        ASSIGN_DIM                                               !3
         77        OP_DATA                                                  ~39
   19    78    >   INIT_FCALL                                               'readdir'
         79        SEND_VAR                                                 !4
         80        DO_ICALL                                         $40     
         81        ASSIGN                                           ~41     !5, $40
         82        TYPE_CHECK                                  1018          ~41
         83      > JMPNZ                                                    ~42, ->16
   42    84    >   INIT_FCALL                                               'closedir'
         85        SEND_VAR                                                 !4
         86        DO_ICALL                                                 
   44    87    > > RETURN                                                   !3
   45    88*     > RETURN                                                   null

End of function directorytoarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.66 ms | 1406 KiB | 31 Q