php-uploader icon indicating copy to clipboard operation
php-uploader copied to clipboard

php 8.1 warning

Open Pok4 opened this issue 3 years ago • 5 comments

[phpBB Debug] PHP Warning: in file C:/xampp2/htdocs/App/Entity/Uploader.php on line 202: Trying to access array offset on value of type int
  On line 202 i have: if($options['maxSize'] && $file['size'][0] > $options['maxSize']) $errors[] = $this->error_messages['max_file_size']; when i cjhange $file['size'][0] to @$file['size'][0] the warning disappear.

Can someone test it on php 8.1 and fix this... ?

Pok4 avatar Apr 12 '22 08:04 Pok4

i fixed by myself, change line to: if($options['maxSize'] && isset($file['size'][0]) && $file['size'][0] > $options['maxSize']) $errors[] = $this->error_messages['max_file_size'];

Pok4 avatar Apr 12 '22 10:04 Pok4

Hi,

Unfortunately this is not a fix, in fact It won't check the size correctly on server side. This code will remove the warning but will not check the size server side...

So this bug should reopened...

lenamtl avatar May 31 '22 12:05 lenamtl

We waiting :)

Pok4 avatar May 31 '22 12:05 Pok4

Hi,

Here is the fix

$file['size'][0] should be replaced by $file['size']

Replace if($options['maxSize'] && $file['size'][0] > $options['maxSize']) $errors[] = $this->error_messages['max_file_size'];

By if($options['maxSize'] && $file['size'] > $options['maxSize']) $errors[] = $this->error_messages['max_file_size'];

Important: I found another error when I compared the $options['maxSize'] VS $file['size'] they use different size format so they cannot be compared

So you need to edit maxSize must be set in bytes not megabytes (because the code does not have any conversion) You need to change the value in Javascript and in PHP.

lenamtl avatar Jun 01 '22 13:06 lenamtl

This bug can be closes now ;)

lenamtl avatar Jun 02 '22 13:06 lenamtl