【发布时间】:2016-05-17 22:04:46
【问题描述】:
我正在使用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));
这在本地工作,但是实时服务器运行的是 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返回与以前相同的错误
【问题讨论】:
标签: php codeigniter curl codeigniter-3 brightcove