Menu

#77 Wrong iteration in site/samples.PHP/jupload.php

v1.0_(example)
pending
nobody
None
1
2014-01-15
2013-11-23
Anonymous
No

site/samples.PHP/jupload.php::receive_uploaded_files() contains the following code:

$cnt = 0;
foreach ($_FILES as $key => $value) {
....
$files_data['name'] = $value['name'][$cnt];
....
$cnt ++;
}

This is wrong in any case. If 'httpUploadParameterType' is set to 'array', which is the default, the structure of $_FILES is:
(
[File] => Array
(
[name] => Array
(
[0] => a
[1] => b
[2] => c
)

        [type] => Array
            (
                [0] => application/octet-stream
                [1] => application/octet-stream
                [2] => application/octet-stream
            )

        [tmp_name] => Array
            (
                [0] => /tmp/phppCDnbm
                [1] => /tmp/php9d4ZlB
                [2] => /tmp/php3uWCwQ
            )

        [error] => Array
            (
                [0] => 0
                [1] => 0
                [2] => 0
            )

        [size] => Array
            (
                [0] => 214
                [1] => 203
                [2] => 329
            )

    )

)

As a result, the code stops working if we allow more than one file per packet.

Discussion

  • Geoff

    Geoff - 2013-11-23

    Please provide:
    - your applet parameters
    - complete debug log (debug level 99)

     

    If 'httpUploadParameterType' is set to 'array', which is the default

    No, 'iteration' is the default. If you want 'array' you must specify so.

    the code stops working if we allow more than one file per packet

    I don't know what you mean by this. If you are referring to nbFilesPerRequest then that has no bearing in the $_FILES array which PHP creates.

    It sounds like you are uploading as 'iteration' when you really want 'array'. Check your applet parameters.

     
    • Anonymous

      Anonymous - 2013-11-24

      Geoff,

      I was reporting a bug in the PHP code, not the applet itself.
      site/samples.PHP directory of jupload-5.0.8 contains jupload.php as a library and after_upload.php, index.php as an example. jupload.php contains the above wrong loop. Also, it sets its own defaults for the applet parameters not set inside index.php. It has the following lines:

      if (!isset($appletparams['httpUploadParameterType']))
      $appletparams['httpUploadParameterType'] = 'array';

      This is what I was talking about. Then, if I set nbFilesPerRequest in index.php to be greater than 1, then the PHP code will handle just one file. The code is wrong in general. In the one-file-per-request case, it works just by a coincidence.

       
  • Anonymous

    Anonymous - 2013-11-24

    Anyway, the patch for jupload.php is attached.

     
  • Geoff

    Geoff - 2013-11-24

    Also, it sets its own defaults for the applet parameters not set inside index.php.

    The values inside jupload.php are overridden by the applet parameters you specify. If I cannot see what you have coded in your 'index.php' then I cannot be certain what values you actually have in jupload.php.

     

    Anyway, the patch for jupload.php is attached.

    Your code will break when mode 'iteration' is used.

     
  • Etienne

    Etienne - 2014-01-15

    Now released (please check the 5.1.0 version).

    Etienne

     
  • Etienne

    Etienne - 2014-01-15
    • status: open --> pending
     

Anonymous
Anonymous

Add attachments
Cancel