I am using the Brightcove API to upload video files from my server to my Brightcove account. I had it working with the following code:
$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));
This was working locally however the live server is running PHP 5.3 so I can't use new CURLFile()
How would I achieve sending the file in a way that will work with PHP 5.3.3? I tried changing the file filed to use the @
syntax instead like so:
'file' => '@' . FCPATH.'assets/uploads/submitted/'.$video->filename
but that doesn't seem to work, the API returns an error saying:
FilestreamRequiredError: upload requires a multipart/form-data POST with a valid filestream
So it looks like the file isn't being posted through.
I've also tried copying the curl_file_create
function like so:
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" : '');
}
And then doing:
'file' => $this->custom_curl_file_create(FCPATH.'assets/uploads/submitted/'.$video->filename)
This doesn't work either though, the API returns the same error as before