Media Write API: PHP Example - Upload Video Sample Code

Video CloudLegacy StudioProfessional, Enterprise

This is sample code for the PHP upload example, an application that uses a PHP page to upload a video to your media library. The PHP script uses the PHP Media API Wrapper, which you can obtain and find instructions for using on the Brightcove Open Source Project site.

The script handles the upload form and uploads the video. You will need to provide valid tokens for your account, replacing [[READ_TOKEN]] and [[WRITE_TOKEN]] with your own tokens.

Code for the form:

    <title>File Upload Form</title>
    <h2>This form allows you to upload a Video to the Brightcove Video Cloud.</h2>
    <form action="BCLuploadVideo.php" method="post" enctype="multipart/form-data"><br>
      <p>Video Name: <input type="text" name="bcVideoName" size="50" /></p>
      <p>Video Description:<br/><textarea name="bcShortDescription" rows="5" cols="50"></textarea></p>
      <p>Type (or select) Filename: <input type="file" name="videoFile"></p>
      <p><input type="submit" value="Upload File"></p>

Code for the PHP script:


  // This code example uses the PHP Media API wrapper
  // For the PHP Media API wrapper, visit

  // Include the BCMAPI Wrapper
  // Instantiate the class, passing it our Brightcove API tokens (read, then write)
  $bc = new BCMAPI(

  // Create an array of meta data from our form fields
  $metaData = array(
    'name' => $_POST['bcVideoName'],
    'shortDescription' => $_POST['bcShortDescription']
  // Move the file out of 'tmp', or rename
  rename($_FILES['videoFile']['tmp_name'], '/tmp/' . $_FILES['videoFile']['name']);
  $file = '/tmp/' . $_FILES['videoFile']['name'];
  // Create a try/catch
  try {
    // Upload the video and save the video ID
    $id = $bc->createMedia('video', $file, $metaData);
          echo 'New video id: ';
          echo $id;
  } catch(Exception $error) {
    // Handle our error
    echo $error;