$headers = array(
"Expect: 100-continue",
"Authorization: Basic " . base64_encode("{$user}:{$password}"),
);
$url = "http://{$host}:{$port}/path?var1=value1%26var2=value2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_TIMEOUT, 600);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//把結果返回給變量
curl_setopt($ch, CURLOPT_VERBOSE, '1');//輸出debug信息
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);//支持跳轉
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);//最多跳轉次數
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_PUT, true );//提交方式
$fp = fopen($file, 'r');
$len = filesize($file);
curl_setopt($ch, CURLOPT_INFILE, $fp );//設置上傳文件的FILE指針
curl_setopt($ch, CURLOPT_INFILESIZE, $len );//設置上傳文件的大小curl
$out = curl_exec($ch);
$errno = curl_errno($ch);
fclose($fp);
curl_close($ch);url