php 通过curl 上传文件:
$fh = fopen('/usr/local/share-icon-link.png', 'r'); curl_setopt($ch,CURLOPT_PUT,true); curl_setopt($ch, CURLOPT_INFILE, $fh); curl_setopt($ch, CURLOPT_INFILESIZE, filesize("/usr/local/share-icon-link.png"));
就设置这3个选项,将php读取的文件内容设置为body 的一部分。
如果要将内容以form 域的形式上传的话,直接设置:
$fields['filename'] = "/data/test.txt";
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);//设置提交的字符串
curl_setopt($ch, CURLOPT_POST, true);
这样就是post的内容上传了。
其他的字段类似 $fields
转载请注明原文地址: https://ju.6miu.com/read-5990.html