Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning Trying to access array offset on value of type int in #1

Closed
lenamtl opened this issue May 27, 2022 · 1 comment
Closed

warning Trying to access array offset on value of type int in #1

lenamtl opened this issue May 27, 2022 · 1 comment

Comments

@lenamtl
Copy link

lenamtl commented May 27, 2022

Hi,

I know this is an old code and the project is an abandonned one...

I need to fix a warning (PHP 8)
Trying to access array offset on value of type int in

related to this line from validate($file = null)
if($options['maxSize'] && $file['size'][0] > $options['maxSize']) $errors[] = $this->error_messages['max_file_size'];

Any clue?

@lenamtl lenamtl changed the title warning warning Trying to access array offset on value of type int in May 27, 2022
@lenamtl
Copy link
Author

lenamtl commented Jun 1, 2022

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 we 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 lenamtl closed this as completed Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant