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

little forgetfulness in Body Class #135

Open
m4ffucci opened this issue Jun 1, 2018 · 0 comments
Open

little forgetfulness in Body Class #135

m4ffucci opened this issue Jun 1, 2018 · 0 comments

Comments

@m4ffucci
Copy link

m4ffucci commented Jun 1, 2018

I needed to send an image file with title and caption from a classic html form to a local php controller. I wanted to forward the form data to a remote webservice with Unirest, to do this I used the following method of the Body class.

 public static function Multipart($data, $files = false)
    {
        if (is_object($data)) {
            return get_object_vars($data);
        }
        if (!is_array($data)) {
            return array($data);
        }
        if ($files !== false) {
            foreach ($files as $name => $file) {
                $data[$name] = call_user_func(array(__CLASS__, 'File'), $file);
            }
        }
        return $data;
    }

The $files parameter is an array of $file, so $file can contain $filename, $mimetype and $postname.

The call_user_func method does not provide for the split of the array elements into individual parameters for Body::File().

I proceeded to fix it just like that:

# Original line
# -------------------------------------------------------------
# $data[$name] = call_user_func(array(__CLASS__, 'File'), $file);

# Fixed line
$data[$name] = call_user_func_array(array(__CLASS__, 'File'), $file);
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