note 62274 modified in function.curl-setopt by danbrown
| From: | danbrown@php.net | Date: | Mon, 20 Jun 2011 14:53:30 +0000 |
| Subject: | note 62274 modified in function.curl-setopt by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180692@lists.php.net to get a copy of this message | ||
The examples below for HTTP file upload work great, but I wanted to be able to post multiple files
through HTTP upload using HTML arrays as specified in example 38.3 at
http://php.net/features.file-upload
In this case, you need to set the arrays AND keys in the $post_data, it will not work with just the
array names. The following example shows how this works:
<?php
$post_data = array();
$post_data['pictures[0]'] = "@cat.jpg";
$post_data['pictures[1]'] = "@dog.jpg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/my_url.php" );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
print "$postResult";
?>
--was--
The examples below for HTTP file upload work great, but I wanted to be able to post multiple files
through HTTP upload using HTML arrays as specified in example 38.3 at
http://us3.php.net/features.file-upload
In this case, you need to set the arrays AND keys in the $post_data, it will not work with just the
array names. The following example shows how this works:
<?php
$post_data = array();
$post_data['pictures[0]'] = "@cat.jpg";
$post_data['pictures[1]'] = "@dog.jpg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/my_url.php" );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
}
curl_close($ch);
print "$postResult";
?>
http://php.net/manual/en/function.curl-setopt.php