3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Multiupload extends MY_Controller { /* ----------------------------------------------------------------------------------- * It's actualy not my own source, but I just want to share & bookmark it here ;) * * Thanks to Anggy Trisnawan * Url: http://anggytrisnawan.com/blog/2012/07/21/upload-multiple-file-codeigniter * ----------------------------------------------------------------------------------- */ function __construct() { parent::__construct(); // load the libraries at first $this->load->library('image_lib'); $this->load->helper(array('form', 'url')); } // front view function index() { /* ----------------------------------------------------------------------------------- * It's what you need for the 'upload' view * ----------------------------------------------------------------------------------- * <?php echo form_open_multipart('upload/do_upload');?> * * <!-- make sure you give an array (userfile[]) to the "name" attribute and have attribute "multiple" on it --> * <?php echo form_input( array( 'name'=>'userfile[]', 'multiple'=>true ) ); ?><br /> * * <!-- just, another submit button --> * <?php echo form_submit('submit', 'Upload'); ?> * * <!-- well, close the form --> * <?php echo form_close();?> * ----------------------------------------------------------------------------------- */ $data['multiupload'] = "multiupload"; // Controller $data['view'] = "form_multiupload"; // View $data['module'] = "multiupload"; // Controller $data['error'] = ' '; echo Modules::run('template/staff', $data); } // Upload & Resize in action function do_upload() { $upload_conf = array( 'upload_path' => realpath('assets/doc/img/real/'), 'allowed_types' => 'gif|jpg|png|JPEG|JPG', 'max_size' => '30000', 'encrypt_name' => TRUE, 'overwrite' => TRUE, ); $this->load->library('upload', $upload_conf); //$this->upload->initialize($upload_conf); foreach ($_FILES['userfile'] as $key => $val) { $i = 1; foreach ($val as $v) { $field_name = "file_" . $i; $_FILES[$field_name][$key] = $v; $i++; } } // Unset the useless one ;) unset($_FILES['userfile']); foreach ($_FILES as $field_name => $file) { if (!$this->upload->do_upload($field_name)) { echo $this->image_lib->display_errors(); } else { $upload_data = $this->upload->data(); $ori = $upload_data['file_name']; $mr = $upload_data['file_path'] . $ori; $this->watermarking($mr); //this is the larger image $config['image_library'] = 'gd2'; $config['source_image'] = $upload_data['full_path']; $config['new_image'] = 'assets/doc/img/full/' . $upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 0; $config['height'] = 0; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //this is the larger image $config['image_library'] = 'gd2'; $config['source_image'] = $upload_data['full_path']; $config['new_image'] = 'assets/doc/img/medium/' . $upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 342; $config['height'] = 342; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //small image $config['image_library'] = 'gd2'; $config['source_image'] = $upload_data['full_path']; $config['new_image'] = 'assets/doc/img/small/' . $upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 152; $config['height'] = 152; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //cropped thumbnail $config['image_library'] = 'gd2'; $config['source_image'] = $upload_data['full_path']; $config['new_image'] = 'assets/doc/img/thumbnails/' . $upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 62; $config['height'] = 62; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); // do it! if (!$this->image_lib->resize()) { // if got fail. //$error['resize'][] = $this->image_lib->display_errors(); echo $this->image_lib->display_errors(); } else { // otherwise, put each upload data to an array. $success[] = $upload_data; } } } // see what we get if (count($error > 0)) { $data['error'] = $error; } else { $data['success'] = $upload_data; } $data['multiupload'] = "multiupload"; // Controller $data['view'] = "index_multiupload"; // View $data['module'] = "multiupload"; // Controller $data['error'] = ' '; dump($this->upload->data()); echo Modules::run('template/staff', $data); } } /* End of File: multiupload.php */
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q2KKH
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DEFINED                                          ~0      'BASEPATH'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->4
    3     3    > > EXIT                                                     'No+direct+script+access+allowed'
    5     4    >   DECLARE_CLASS                                            'multiupload', 'my_controller'
  172     5      > RETURN                                                   1

Class Multiupload:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q2KKH
function name:  __construct
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_STATIC_METHOD_CALL                                  
          1        DO_FCALL                                      0          
   18     2        FETCH_OBJ_R                                      ~1      'load'
          3        INIT_METHOD_CALL                                         ~1, 'library'
          4        SEND_VAL_EX                                              'image_lib'
          5        DO_FCALL                                      0          
   19     6        FETCH_OBJ_R                                      ~3      'load'
          7        INIT_METHOD_CALL                                         ~3, 'helper'
          8        SEND_VAL_EX                                              <array>
          9        DO_FCALL                                      0          
   20    10      > RETURN                                                   null

End of function __construct

Function index:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q2KKH
function name:  index
number of ops:  14
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   ASSIGN_DIM                                               !0, 'multiupload'
          1        OP_DATA                                                  'multiupload'
   41     2        ASSIGN_DIM                                               !0, 'view'
          3        OP_DATA                                                  'form_multiupload'
   42     4        ASSIGN_DIM                                               !0, 'module'
          5        OP_DATA                                                  'multiupload'
   43     6        ASSIGN_DIM                                               !0, 'error'
          7        OP_DATA                                                  '+'
   45     8        INIT_STATIC_METHOD_CALL                                  'Modules', 'run'
          9        SEND_VAL_EX                                              'template%2Fstaff'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $5      
         12        ECHO                                                     $5
   46    13      > RETURN                                                   null

End of function index

Function do_upload:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 32
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 32
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 30
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 30
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 30
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 37, Position 2 = 175
Branch analysis from position: 37
2 jumps found. (Code = 78) Position 1 = 38, Position 2 = 175
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 50
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 174
Branch analysis from position: 174
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 167, Position 2 = 172
Branch analysis from position: 167
1 jumps found. (Code = 42) Position 1 = 174
Branch analysis from position: 174
Branch analysis from position: 172
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 175
2 jumps found. (Code = 43) Position 1 = 179, Position 2 = 182
Branch analysis from position: 179
1 jumps found. (Code = 42) Position 1 = 184
Branch analysis from position: 184
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 182
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 175
Branch analysis from position: 32
filename:       /in/Q2KKH
function name:  do_upload
number of ops:  204
compiled vars:  !0 = $upload_conf, !1 = $val, !2 = $key, !3 = $i, !4 = $v, !5 = $field_name, !6 = $file, !7 = $upload_data, !8 = $ori, !9 = $mr, !10 = $config, !11 = $success, !12 = $error, !13 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   INIT_FCALL                                               'realpath'
          1        SEND_VAL                                                 'assets%2Fdoc%2Fimg%2Freal%2F'
          2        DO_ICALL                                         $14     
          3        INIT_ARRAY                                       ~15     $14, 'upload_path'
   54     4        ADD_ARRAY_ELEMENT                                ~15     'gif%7Cjpg%7Cpng%7CJPEG%7CJPG', 'allowed_types'
   55     5        ADD_ARRAY_ELEMENT                                ~15     '30000', 'max_size'
   53     6        ADD_ARRAY_ELEMENT                                ~15     <true>, 'encrypt_name'
          7        ADD_ARRAY_ELEMENT                                ~15     <true>, 'overwrite'
   51     8        ASSIGN                                                   !0, ~15
   60     9        FETCH_OBJ_R                                      ~17     'load'
         10        INIT_METHOD_CALL                                         ~17, 'library'
         11        SEND_VAL_EX                                              'upload'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
   64    14        FETCH_R                      global              ~19     '_FILES'
         15        FETCH_DIM_R                                      ~20     ~19, 'userfile'
         16      > FE_RESET_R                                       $21     ~20, ->32
         17    > > FE_FETCH_R                                       ~22     $21, !1, ->32
         18    >   ASSIGN                                                   !2, ~22
   66    19        ASSIGN                                                   !3, 1
   67    20      > FE_RESET_R                                       $25     !1, ->30
         21    > > FE_FETCH_R                                               $25, !4, ->30
   70    22    >   CONCAT                                           ~26     'file_', !3
         23        ASSIGN                                                   !5, ~26
   71    24        FETCH_W                      global              $28     '_FILES'
         25        FETCH_DIM_W                                      $29     $28, !5
         26        ASSIGN_DIM                                               $29, !2
         27        OP_DATA                                                  !4
   72    28        PRE_INC                                                  !3
   67    29      > JMP                                                      ->21
         30    >   FE_FREE                                                  $25
   64    31      > JMP                                                      ->17
         32    >   FE_FREE                                                  $21
   77    33        FETCH_UNSET                                      $32     '_FILES'
         34        UNSET_DIM                                                $32, 'userfile'
   79    35        FETCH_R                      global              ~33     '_FILES'
         36      > FE_RESET_R                                       $34     ~33, ->175
         37    > > FE_FETCH_R                                       ~35     $34, !6, ->175
         38    >   ASSIGN                                                   !5, ~35
   81    39        FETCH_OBJ_R                                      ~37     'upload'
         40        INIT_METHOD_CALL                                         ~37, 'do_upload'
         41        SEND_VAR_EX                                              !5
         42        DO_FCALL                                      0  $38     
         43        BOOL_NOT                                         ~39     $38
         44      > JMPZ                                                     ~39, ->50
   83    45    >   FETCH_OBJ_R                                      ~40     'image_lib'
         46        INIT_METHOD_CALL                                         ~40, 'display_errors'
         47        DO_FCALL                                      0  $41     
         48        ECHO                                                     $41
         49      > JMP                                                      ->174
   87    50    >   FETCH_OBJ_R                                      ~42     'upload'
         51        INIT_METHOD_CALL                                         ~42, 'data'
         52        DO_FCALL                                      0  $43     
         53        ASSIGN                                                   !7, $43
   89    54        FETCH_DIM_R                                      ~45     !7, 'file_name'
         55        ASSIGN                                                   !8, ~45
   90    56        FETCH_DIM_R                                      ~47     !7, 'file_path'
         57        CONCAT                                           ~48     ~47, !8
         58        ASSIGN                                                   !9, ~48
   92    59        INIT_METHOD_CALL                                         'watermarking'
         60        SEND_VAR_EX                                              !9
         61        DO_FCALL                                      0          
   95    62        ASSIGN_DIM                                               !10, 'image_library'
         63        OP_DATA                                                  'gd2'
   96    64        FETCH_DIM_R                                      ~53     !7, 'full_path'
         65        ASSIGN_DIM                                               !10, 'source_image'
         66        OP_DATA                                                  ~53
   97    67        FETCH_DIM_R                                      ~55     !7, 'file_name'
         68        CONCAT                                           ~56     'assets%2Fdoc%2Fimg%2Ffull%2F', ~55
         69        ASSIGN_DIM                                               !10, 'new_image'
         70        OP_DATA                                                  ~56
   98    71        ASSIGN_DIM                                               !10, 'maintain_ratio'
         72        OP_DATA                                                  <true>
   99    73        ASSIGN_DIM                                               !10, 'width'
         74        OP_DATA                                                  0
  100    75        ASSIGN_DIM                                               !10, 'height'
         76        OP_DATA                                                  0
  101    77        FETCH_OBJ_R                                      ~60     'image_lib'
         78        INIT_METHOD_CALL                                         ~60, 'initialize'
         79        SEND_VAR_EX                                              !10
         80        DO_FCALL                                      0          
  102    81        FETCH_OBJ_R                                      ~62     'image_lib'
         82        INIT_METHOD_CALL                                         ~62, 'resize'
         83        DO_FCALL                                      0          
  103    84        FETCH_OBJ_R                                      ~64     'image_lib'
         85        INIT_METHOD_CALL                                         ~64, 'clear'
         86        DO_FCALL                                      0          
  107    87        ASSIGN_DIM                                               !10, 'image_library'
         88        OP_DATA                                                  'gd2'
  108    89        FETCH_DIM_R                                      ~68     !7, 'full_path'
         90        ASSIGN_DIM                                               !10, 'source_image'
         91        OP_DATA                                                  ~68
  109    92        FETCH_DIM_R                                      ~70     !7, 'file_name'
         93        CONCAT                                           ~71     'assets%2Fdoc%2Fimg%2Fmedium%2F', ~70
         94        ASSIGN_DIM                                               !10, 'new_image'
         95        OP_DATA                                                  ~71
  110    96        ASSIGN_DIM                                               !10, 'maintain_ratio'
         97        OP_DATA                                                  <true>
  111    98        ASSIGN_DIM                                               !10, 'width'
         99        OP_DATA                                                  342
  112   100        ASSIGN_DIM                                               !10, 'height'
        101        OP_DATA                                                  342
  113   102        FETCH_OBJ_R                                      ~75     'image_lib'
        103        INIT_METHOD_CALL                                         ~75, 'initialize'
        104        SEND_VAR_EX                                              !10
        105        DO_FCALL                                      0          
  114   106        FETCH_OBJ_R                                      ~77     'image_lib'
        107        INIT_METHOD_CALL                                         ~77, 'resize'
        108        DO_FCALL                                      0          
  115   109        FETCH_OBJ_R                                      ~79     'image_lib'
        110        INIT_METHOD_CALL                                         ~79, 'clear'
        111        DO_FCALL                                      0          
  119   112        ASSIGN_DIM                                               !10, 'image_library'
        113        OP_DATA                                                  'gd2'
  121   114        FETCH_DIM_R                                      ~83     !7, 'full_path'
        115        ASSIGN_DIM                                               !10, 'source_image'
        116        OP_DATA                                                  ~83
  122   117        FETCH_DIM_R                                      ~85     !7, 'file_name'
        118        CONCAT                                           ~86     'assets%2Fdoc%2Fimg%2Fsmall%2F', ~85
        119        ASSIGN_DIM                                               !10, 'new_image'
        120        OP_DATA                                                  ~86
  123   121        ASSIGN_DIM                                               !10, 'maintain_ratio'
        122        OP_DATA                                                  <true>
  124   123        ASSIGN_DIM                                               !10, 'width'
        124        OP_DATA                                                  152
  125   125        ASSIGN_DIM                                               !10, 'height'
        126        OP_DATA                                                  152
  126   127        FETCH_OBJ_R                                      ~90     'image_lib'
        128        INIT_METHOD_CALL                                         ~90, 'initialize'
        129        SEND_VAR_EX                                              !10
        130        DO_FCALL                                      0          
  127   131        FETCH_OBJ_R                                      ~92     'image_lib'
        132        INIT_METHOD_CALL                                         ~92, 'resize'
        133        DO_FCALL                                      0          
  128   134        FETCH_OBJ_R                                      ~94     'image_lib'
        135        INIT_METHOD_CALL                                         ~94, 'clear'
        136        DO_FCALL                                      0          
  131   137        ASSIGN_DIM                                               !10, 'image_library'
        138        OP_DATA                                                  'gd2'
  133   139        FETCH_DIM_R                                      ~98     !7, 'full_path'
        140        ASSIGN_DIM                                               !10, 'source_image'
        141        OP_DATA                                                  ~98
  134   142        FETCH_DIM_R                                      ~100    !7, 'file_name'
        143        CONCAT                                           ~101    'assets%2Fdoc%2Fimg%2Fthumbnails%2F', ~100
        144        ASSIGN_DIM                                               !10, 'new_image'
        145        OP_DATA                                                  ~101
  135   146        ASSIGN_DIM                                               !10, 'maintain_ratio'
        147        OP_DATA                                                  <true>
  136   148        ASSIGN_DIM                                               !10, 'width'
        149        OP_DATA                                                  62
  137   150        ASSIGN_DIM                                               !10, 'height'
        151        OP_DATA                                                  62
  138   152        FETCH_OBJ_R                                      ~105    'image_lib'
        153        INIT_METHOD_CALL                                         ~105, 'initialize'
        154        SEND_VAR_EX                                              !10
        155        DO_FCALL                                      0          
  139   156        FETCH_OBJ_R                                      ~107    'image_lib'
        157        INIT_METHOD_CALL                                         ~107, 'resize'
        158        DO_FCALL                                      0          
  140   159        FETCH_OBJ_R                                      ~109    'image_lib'
        160        INIT_METHOD_CALL                                         ~109, 'clear'
        161        DO_FCALL                                      0          
  143   162        FETCH_OBJ_R                                      ~111    'image_lib'
        163        INIT_METHOD_CALL                                         ~111, 'resize'
        164        DO_FCALL                                      0  $112    
        165        BOOL_NOT                                         ~113    $112
        166      > JMPZ                                                     ~113, ->172
  146   167    >   FETCH_OBJ_R                                      ~114    'image_lib'
        168        INIT_METHOD_CALL                                         ~114, 'display_errors'
        169        DO_FCALL                                      0  $115    
        170        ECHO                                                     $115
        171      > JMP                                                      ->174
  149   172    >   ASSIGN_DIM                                               !11
        173        OP_DATA                                                  !7
   79   174    > > JMP                                                      ->37
        175    >   FE_FREE                                                  $34
  155   176        IS_SMALLER                                       ~117    0, !12
        177        COUNT                                            ~118    ~117
        178      > JMPZ                                                     ~118, ->182
  156   179    >   ASSIGN_DIM                                               !13, 'error'
        180        OP_DATA                                                  !12
        181      > JMP                                                      ->184
  158   182    >   ASSIGN_DIM                                               !13, 'success'
        183        OP_DATA                                                  !7
  161   184    >   ASSIGN_DIM                                               !13, 'multiupload'
        185        OP_DATA                                                  'multiupload'
  162   186        ASSIGN_DIM                                               !13, 'view'
        187        OP_DATA                                                  'index_multiupload'
  163   188        ASSIGN_DIM                                               !13, 'module'
        189        OP_DATA                                                  'multiupload'
  164   190        ASSIGN_DIM                                               !13, 'error'
        191        OP_DATA                                                  '+'
  166   192        INIT_FCALL_BY_NAME                                       'dump'
        193        FETCH_OBJ_R                                      ~125    'upload'
        194        INIT_METHOD_CALL                                         ~125, 'data'
        195        DO_FCALL                                      0  $126    
        196        SEND_VAR_NO_REF_EX                                       $126
        197        DO_FCALL                                      0          
  168   198        INIT_STATIC_METHOD_CALL                                  'Modules', 'run'
        199        SEND_VAL_EX                                              'template%2Fstaff'
        200        SEND_VAR_EX                                              !13
        201        DO_FCALL                                      0  $128    
        202        ECHO                                                     $128
  169   203      > RETURN                                                   null

End of function do_upload

End of class Multiupload.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.65 ms | 1416 KiB | 15 Q