下面是一段示例代码:
// 注: PHP 5.5.0起,文件上传建议使用CURLFile代替@
// 多文件上传
$data = array(
'input_file[0]' => new CURLFile('d:/1.txt', 'text/plain', 'testfile.txt'),
'input_file[1]' => new CURLFile('d:/2.txt', 'text/plain'),
'input_file[2]' => new CURLFile('d:/3.txt', 'text/plain'),
);
$ch = curl_init('http://demo.zjmainstay.cn/php/curl/curlUploadHandler.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
如果你的版本比较低,文件部分使用:
'input_file[0]' => '@d:/1.txt',
这样既可。
我的博客《PHP cURL实现模拟登录与采集使用方法详解》对各类curl问题做了系统而详细的讲解,请参考“十、模拟上传文件”部分查看更多文件上传内容,如直接基于采集的文件内容进行上传等。