Is there a way using PHP curl to send multiple files in a single request?
I understand you can send a single file making use of the following:
$fh = fopen("files/" . $title . "/" . $name, "w");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
But I want to be able to write lets say 3 files using a single request.
Is there maybe a way to write bytes to the request before the curl_exec()
?
You can use this
I searched a way to send a post request with multiple files using curl. But all code examples did not do the same as a browser does. The $_FILES global did not contain the usual array as documented by PHP.
Now i found out why: the offsets where missing the [i]
see http://php.net/manual/de/class.curlfile.php#121971
Without the "trick" you would get a different result in $_FILES
or
But this is not what we want.
What we want is the usual $_FILES array like
Here the code:
Example:
A complete example would look something like this :