Table of content

Upload with PHP SDK


Using our SDKs is the fastest and easiest way to programmatically upload videos on Dailymotion.

Follow this PHP tutorial to learn how to add a video on our servers and publish it on your Dailymotion channel


Prerequisites

To upload videos on your Dailymotion channel using our PHP SDK, you first need to:


Step 1: Authentication on Dailymotion via our API

You need to authenticate yourself against the API to gain access to the Dailymotion account on which the video will be uploaded.
Uploading videos requires the manage_videos scope

#!/usr/bin/env php 
<?php

require_once 'Dailymotion.php';

// Account settings - Replace the <credentials> below with your own
$apiKey        = '<yourApiKey>';
$apiSecret     = '<yourApiSecret>';
$testUser      = '<someUser>';
$testPassword  = '<yourPassword>';

// Scopes you need to run your tests
$scopes = array(
    'manage_videos',
);

// Dailymotion object instantiation
$api = new Dailymotion();
$api->setGrantType(
    Dailymotion::GRANT_TYPE_PASSWORD,
    $apiKey,
    $apiSecret,
    $scopes,
    array(
        'username' => $testUser,
        'password' => $testPassword,
    )
);

See our authentication guide for more details


Step 2: Upload a video on Dailymotion with our PHP SDK

The PHP SDK allows you to interact with the Platform API to upload videos on our platform in 2 steps (upload/create).
The titlechannel and is_created_for_kids fields are mandatory to publish a video. 

// 1. Upload your file on Dailymotion's servers
// Replace with the path to your video
$url = $api->uploadFile('/path/to/your/video.mp4');

// 2. Create the video on your channel - Replace with your <CHANNEL_ID>
$api->post(
    '/user/<CHANNEL_ID>/videos',
    array(
        'url'       => $url,
        'title'     => 'Dailymotion PHP SDK upload test',
        'channel'   => 'videogames',
        'published' => true,
        'is_created_for_kids' => false,
    )
);

Set 'published' => false if you don’t want to publish the video immediately. It will be saved as a draft.

Note:

The channel object represents a category of videos. Check the full list of available categories.


Not coding in PHP? :

Visit our SDKs documentation and find your preferred language!