请教用Curl 在php 里面模拟表单提交 文本+文件的写法

2025-05-08 16:05:17
推荐回答(1个)
回答1:

我的博客《PHP cURL实现模拟登录与采集使用方法详解教程》已经有了很多示例,
请直接搜索打开文章查看。

    // 注: PHP 5.5.0起,文件上传建议使用CURLFile代替@
    // 多文件上传
    $data = array(
        'author'        => 'Zjmainstay',
        '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'),
    );
    $url = '这里省略链接';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_exec($ch);