note 62274 modified in ref.curl by danbrown

From: Date: Sun, 17 May 2009 19:24:57 +0000
Subject: note 62274 modified in ref.curl by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155229@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://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"; ?> --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://my.domain.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/ref.curl.php

« previous php.notes (#155229) next »