在php curl中发布文件

I'm trying to post a file using curl due to this rest api using a multiform.

Here's what I currently have.

    $curlFile = new \CURLFile("shirt.png");
    $data = array
    (
        "apikey" => $key,
        "isTgaUploadEnabled" => "True",
        "onVerificationPage" => "False",
        "file" => $curlFile,
    );

    curl_setopt_array($curl, array(
        CURLOPT_HEADER => TRUE,
        CURLOPT_POST => TRUE,
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_POSTFIELDS => $data,
    ));

It doesn't work using the CURLFile class, any suggestions on what I should do?

You are looking for this on PHP5.5 and above:

$file = new CURLFile('cats.jpg','image/jpeg','test_name');
$args= array('test_file' => $file);

Or this on PHP5.4 or below:

$args['file'] = '@/path/to/file';

Just don't forget to set appropriate flags:

curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);

https://wiki.php.net/rfc/curl-file-upload

http://php.net/manual/en/class.curlfile.php

http://php.net/manual/en/curlfile.construct.php