search

Home  >  Q&A  >  body text

html - php如何用cURL模拟一表单中同时有字符串和文件?

RT,php,想用curl同时发送文件和字符串,就是模拟一个表单中既有一堆字符串还有文件。

巴扎黑巴扎黑2901 days ago432

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-10 14:32:40

    curl_setopt($curl_handle, CURLOPT_POST, 1);
    $args['file'] = '@/path/to/file';
    $args['a'] = 'blablabla...'; //and so on
    curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);
    

    更多的内容:https://wiki.php.net/rfc/curl-file-upload

    reply
    0
  • 迷茫

    迷茫2017-04-10 14:32:40

    默认表单是没法同时POST字符串和文件的,可以考虑字符串用GET通过URL传递,同时POST文件。

    reply
    0
  • Cancelreply