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

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

WBOY
WBOYOriginal
2016-06-06 20:49:201089browse

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

回复内容:

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

<code>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);
</code>

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

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn