【发布时间】:2011-08-06 01:20:18
【问题描述】:
我有一个基本的上传表单,我想使用 cURL 进行模拟。
<?php
$params = array(
'api_key' => $api_key,
'api_secret' => $api_secret,
'urls' => null,
'uids' => 'all',
'detector' => 'Aggressive',
'namespace' => 'face.auth');
$action = $url . '?' . http_build_query($params);
?>
<form enctype="multipart/form-data" method="post" action="<?php echo $action; ?>">
<input type="file" name="upload" id="upload">
<input type="submit" />
</form>
我知道如何使用 cURL 发布,但我不确定如何发布图像数据(此数据作为二进制数据存储在数据库中,我们称之为 $binary)。传递$binary 如下所示作为邮递区不起作用。我看过一些示例,它们将@ 放在文件名/路径前面,并将其作为后域发送。但是,这似乎对我不起作用(因为我处理的是二进制数据,而不是文件名/路径)。
$params = array(
'api_key' => $api_key,
'api_secret' => $api_secret,
'urls' => null,
'uids' => 'all',
'detector' => 'Aggressive',
'namespace' => 'face.auth',
$binary);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
var_dump($data);
?>
我也试过了:
$params = array(
'api_key' => $api_key,
'api_secret' => $api_secret,
'urls' => null,
'uids' => 'all',
'detector' => 'Aggressive',
'namespace' => 'face.auth');
$action = $url . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $action);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $binary);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
任何帮助将不胜感激。
【问题讨论】:
-
如果它可以从文件中工作,您可以将二进制数据放入
tmpfile()。 -
您可以制作一个临时文件并使用@file 发送