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