我正在使用Brightcove API,将视频文件从我的服务器上传到我的Brightcove账户。以下是我使用的代码:
$fields = array(
'json' => json_encode( array(
'method' => "create_video",
'params' => array(
'video' => array(
'name' => $video->submission_by_name.' '.time(),
'shortDescription' => $video->submission_question_1
),
"token" => $this->config->item('brightcove_write_token'),
"encode_to" => "MP4",
"create_multiple_renditions" => "True"
))
),
'file' => new CURLFile(FCPATH.'assets/uploads/submitted/'.$video->filename)
);
//open connection
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $this->config->item('brightcove_write_endpoint'));
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = json_decode(curl_exec($ch));
这在本地可以正常工作,但是live服务器正在运行PHP 5.3,所以我不能使用new CURLFile()
我该如何以适用于PHP 5.3.3的方式发送文件? 我尝试使用@
语法来更改文件字段,就像这样:
'file' => '@' . FCPATH.'assets/uploads/submitted/'.$video->filename
但是似乎不起作用,API返回错误信息:
FilestreamRequiredError: upload requires a multipart/form-data POST with a valid filestream
看起来文件没有被发布。
我也尝试像这样复制curl_file_create
函数:
private function custom_curl_file_create($filename, $mimetype = '', $postname = '')
{
if($mimetype=='') {
$mimetype = mime_content_type($filename);
}
return "@$filename;filename="
. ($postname ?: basename($filename))
. ($mimetype ? ";type=$mimetype" : '');
}
然后执行:
'file' => $this->custom_curl_file_create(FCPATH.'assets/uploads/submitted/'.$video->filename)
然而这也不起作用,API 返回之前相同的错误