1. 程式人生 > >PHP中CURL傳輸多個檔案

PHP中CURL傳輸多個檔案

以下是PHP操作CURL傳輸多個檔案的demo


$param = array(
    'file_one' => curl_file_create('/home/images/a.jpg'),
    'file_two' => curl_file_create('/home/images/b.png'),
    'test' => 'test'
);

$url = 'http://ceshi/a/b';
$ch = curl_init($url);                                   //初始化CURL
curl_setopt($ch, CURLOPT_POST,1);    
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);            //POST請求
$result = curl_exec($ch);                                //執行
print_r($result );
 
//服務端接收
$file = $_FILES;
$post = $_POST