三种方式:
1. post
curl_setopt($s, CURLOPT_URL, $url);
curl_setopt($s, CURLOPT_POST, true);
curl_setopt($s, CURLOPT_POSTFIELDS, array('file'=>'@'.$filePath));
2. put
curl_setopt($s, CURLOPT_URL, $url);
curl_setopt($s, CURLOPT_PUT, true);
$fp = fopen($filePath, 'r');
curl_setopt($s, CURLOPT_INFILE, $fp);
curl_setopt($s, CURLOPT_INFILESIZE, filesize($filePath));
3. put
不依赖本地文件,直接上传内存中的文件内容
curl_setopt($s, CURLOPT_URL, $url);
$content = file_get_contents($filePath);
curl_setopt($s, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($s, CURLOPT_POSTFIELDS, $content);
ps: python put binary data
c = pycurl.Curl()
c.setopt(c.URL, uploadUrl)
c.setopt(c.CUSTOMREQUEST, 'PUT')
p = '/your/file/path'
post_data = open(p,'rb').read()
c.setopt(c.POSTFIELDS,post_data)