Gargron / fileupload

PHP FileUpload library that supports chunked uploads
MIT License
459 stars 87 forks source link

ErrorException: "A non well formed numeric value encountered" in PHP 7.1 #56

Closed gthedev closed 7 years ago

gthedev commented 7 years ago

When using this library on PHP 7.1 an exception is thrown: A non well formed numeric value encountered

It is thrown from FileUpload::getConfigBytes method:

protected function getConfigBytes($val)
    {
        $val  = trim($val);
        $last = strtolower($val[strlen($val) - 1]);

        switch ($last) {
            case 'g':
                $val *= 1024;
            case 'm':
                $val *= 1024;
            case 'k':
                $val *= 1024;
        }

        return $this->fixIntegerOverflow($val);
    }

My set up that triggers this error (in a Laravel 5.2 app):

        $sizeValidator = new \FileUpload\Validator\SizeValidator((4*1024*1024));

        // Simple path resolver, where uploads will be put
        $pathResolver = new \FileUpload\PathResolver\Simple(public_path() . '/uploads/' . $uploadPath);

        $filesystem = new \FileUpload\FileSystem\Simple();

        // FileUploader itself
        $fileupload = new \FileUpload\FileUpload($_FILES['files'], $_SERVER);

        // Adding it all together. Note that you can use multiple validators or none at all
        $fileupload->setPathResolver($pathResolver);
        $fileupload->setFileSystem($filesystem);
        $fileupload->addValidator($sizeValidator);

        // Doing the deed
        list($files, $headers) = $fileupload->processAll();

Backtrace:

at FileUpload->getConfigBytes('4M') in FileUpload.php line 532
at FileUpload->validate('/tmp/php28Mk6i', object(File), '0', '0') in FileUpload.php line 367
at FileUpload->process('/tmp/php28Mk6i', 'blank_keyboard_2012_front.jpg', '63221', 'image/jpeg', '0', '0', null) in FileUpload.php line 288
at FileUpload->processAll() in MediaAdminController.php line 207
adelowo commented 7 years ago

This was fixed last year in https://github.com/Gargron/fileupload/pull/33 .. What version of fileupload are you using ?

I would be interested in helping out if there are still issues

adelowo commented 7 years ago

You are using an older version (the code you posted differs from what is here https://github.com/Gargron/fileupload/blob/master/src/FileUpload/FileUpload.php#L521-L538).. Please upgrade

gthedev commented 7 years ago

After pulling master for a fix I have noticed it is different, and is in fact fixed. My apologies, I have not realised someone fixed the version to 1.1.1 in the composer file. After upgrading issue was fixed and therefore this is closed. Thank you!