CreativeDream / php-uploader

PHP File Uploader is an easy to use, hi-performance File Upload Script which allows you to upload files to webserver
MIT License
94 stars 51 forks source link

php 8.1 warning #26

Open Pok4 opened 2 years ago

Pok4 commented 2 years ago

[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 commented 2 years ago

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'];

lenamtl commented 2 years ago

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...

Pok4 commented 2 years ago

We waiting :)

lenamtl commented 2 years ago

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 commented 2 years ago

This bug can be closes now ;)