top button
Flag Notify
Site Registration

video upload sample code in php?

+2 votes
357 views

Hello,

Can any one provide me sample code or links for video upload and retrieve and play in php.

Database is mySQL

posted Oct 13, 2014 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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:

<html>
  <head>
    <title>File Upload Form</title>
  </head>
  <body>
    <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>
    </form>
  </body>

Code for the PHP script:

  <?php

  // This code example uses the PHP Media API wrapper
  // For the PHP Media API wrapper, visit http://docs.brightcove.com/en/video-cloud/open-source/index.html

  // Include the BCMAPI Wrapper
  require('bc-mapi.php');

  // Instantiate the class, passing it our Brightcove API tokens (read, then write)
  $bc = new BCMAPI(
    '[[READ_TOKEN]]',
    '[[WRITE_TOKEN]]'
  );

  // 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;
    die();
  }
?>
answer Oct 16, 2014 by Rahul Singh
Similar Questions
0 votes

I have php script form which I used to input Members Details of my system into the MySQL database. My requirement is to display the last member's details in a input box.

...