In this topic you will learn how to upload videos to your Video Cloud account through a PHP form.
We'll be using PHP Media API Wrapper from opensource.brightcove.com.
First, let's look at the form:
<form method="post" action="BCLuploadVideo.php" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="8000000" /> Title: <input type="text" name="bcVideoName" /><br /> Short Description: <textarea name="bcShortDescription"></textarea><br /> File: <input type="file" name="videoFile" /><br /> <input type="submit" /> </form>
As you can see we've created a simple upload form that posts our data to another page. We're sending along a title, a short description, and the video file.
Now, here's the code for the form handler:
<?php # Include & Instantiate require('bc-mapi.php'); $bc = new BCMAPI( 'z9Jp-c3-KhWc4fqNf1JWz6SkLDlbO0m8UAwOjDBUSt0.', 'z9Jp-c3-KhWdkasdf74kaisaDaIK7239skaoKWUAwOjDBUSt0..' ); # Create new metadata $metaData = array( 'name' => $_POST['bcVideoName'], 'shortDescription' => $_POST['bcShortDescription'] ); # Rename the video file $file = $_FILES['videoFile']; rename($file['tmp_name'], '/tmp/' . $file['name']); $file_location = '/tmp/' . $file['name']; # Send video to Brightcove $id = $bc->createMedia('video', $file_location, $metaData); ?>
In the first few lines, we're simply including the PHP Media API Wrapper and instantiating it with our Media API Read and Write tokens. Next we're setting the metadata for our video; in this example we'll just supply a name and short description. You can pass any item from the Video DTO, though. The next step is a bit more difficult. When a file is uploaded onto the server, it is placed in our temporary directory and given a random string as a name; because Video Cloud only accepts specific file types, we need to rename the file to include its file extension. The easiest way is to simply rename the file to its original file name. Now all we have to do is call our createMedia method from the PHP MAPI Wrapper, passing in the file location and our metadata for the new video. This method returns the Video ID of the newly uploaded file, which we can save for use later on.
If you are having problems getting your videos to upload, Brightcove Support is available to help. You can submit a case here. To make sure you get the fastest response possible, below is a list of what support will need to solve the problem.
After your case is submitted, you will receive an email confirmation from Brightcove Support. To provide additional information on your case to Brightcove Support, reply to the confirmation email.