Wrong iteration in site/samples.PHP/jupload.php
A tool for web developpers, to get rid of HTML upload limitation
Brought to you by:
etienne_sf
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.
Anonymous
Please provide:
No, 'iteration' is the default. If you want 'array' you must specify so.
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.
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.
Anyway, the patch for jupload.php is attached.
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.
Your code will break when mode 'iteration' is used.
Fixed code uploaded to SVN:
https://sourceforge.net/p/jupload/code/1669/tree/trunk/src/site/resources/samples.PHP/jupload.php
Regression tested the 24 possible permutations.
Last edit: Geoff 2013-11-24
Now released (please check the 5.1.0 version).
Etienne