0

Im generating a POST request:

$data['v'] = '2';
$data['file'] = gz compressed data

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);

After this, the "file" field gets lost - it wont arrive to the server, all others do. What can I do?

4

1 回答 1

2

上传文件时,需要文件curl的完整路径(不要忘记在前面加上“@”符号),而不是二进制数据:

$data = array(
    'file' => "@/path/to_your_file_not_binary_data",
    'v' => '2'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

见这里:http ://www.php.net/manual/en/function.curl-setopt.php

此外,如果您需要指定Content-Type标题:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
于 2013-03-10T20:54:51.580 回答