我必须将文件发送到API。 API documentation提供了如何通过文件上载脚本($ _FILES)执行此操作的示例。但是,我在同一台机器上有文件,所以想跳过这一步,直接读入文件以节省时间。
如何阅读文件(视频)以便它可以使用此代码段?
我知道FILES是一个数组,但我可以单独设置它的其他部分(文件名),我真的需要以相同的格式读取它的数据部分才能使用这个代码(我做使用fread?文件获取内容?)
<?php
# Include & Instantiate
require('../echove.php');
$bc = new Echove(
'z9Jp-c3-KhWc4fqNf1JWz6SkLDlbO0m8UAwOjDBUSt0.',
'z9Jp-c3-KhWdkasdf74kaisaDaIK7239skaoKWUAwOjDBUSt0..'
);
# Create new metadata
$metaData = array(
'name' => $_POST['title'],
'shortDescription' => $_POST['shortDescription']
);
# Rename the video file
$file = $_FILES['video'];
rename($file['tmp_name'], '/tmp/' . $file['name']);
$file_location = '/tmp/' . $file['name'];
# Send video to Brightcove
$id = $bc->createVideo($file_location, $metaData);
&GT;
提前感谢您的帮助!
答案 0 :(得分:2)
呃 - 您需要做的就是提供位置,而不是文件句柄或其他任何东西,不是吗?
$files = $_FILES['video'];
$filename = $files['name'];
$file_location = '/home/username/' . $filename; // maybe append the extension
$id = $bc->createVideo($file_location, $metaData);
或更简单
$id = $bc->createVideo( '/foo/bar/baz.txt', $metaData );
答案 1 :(得分:2)
看起来除了指向本地磁盘上的文件外,您不需要做任何事情。怎么样:
<?php
# Include & Instantiate
require('../echove.php');
$bc = new Echove(
'z9Jp-c3-KhWc4fqNf1JWz6SkLDlbO0m8UAwOjDBUSt0.',
'z9Jp-c3-KhWdkasdf74kaisaDaIK7239skaoKWUAwOjDBUSt0..'
);
# Create new metadata
$metaData = array(
'name' => $_POST['title'],
'shortDescription' => $_POST['shortDescription']
);
# point at some file already on disk
$file_location = '/path/to/my/file.dat'; // <== if the file is already on the box, just set $file_location with the pathname and bob's yer uncle
# Send video to Brightcove
$id = $bc->createVideo($file_location, $metaData);