Uploading videos in bulk from your PC to your Ziggeo Application through Ziggeo SDK

If you have a lot of videos on your personal devices and want to transfer them to Ziggeo you could try doing it through the SDK. In specific, we have PHP SDK demo that shows you how to do that from start to finish. You can grab it from here: Multiple videos upload from PC/Mac demo. The first where we start off is the HTML part of the page. This is shown to us right away and allows us to set everything locally right at the start.
[code language="html"]
<form method="POST" action="" enctype="multipart/form-data">
[/code]
The form declaration tells us the type of request that will be made when we submit and the important part of it would be the part that tells us to upload the videos and send them over - the enctype attribute. It being set to "multipart/form-data" tells the browser to not only pass the file path to us, rather to send the videos instead.
[code language="html"]
<input name="submitted" type="hidden" value="submitted">
[/code]
This is a hidden field to help us easily detect submission (since the same would never be set if you just open your page).
[code language="html"]
<input name="files[]" type="file" multiple>
[/code]
This one is also very important to be set. There are 2 tricks that we are doing with it: 1. Telling it to return an array of element rather than just one video 2. We are telling it to allow us to select multiple files (not just the default single file) * check out the [] at the end of the name attribute. It tells PHP that it is an array that we are sending. So if it is missing, you will be getting only a single video instead all of those that you selected. We will also use it without [] in our PHP code, so it is good to use "files" or something similar for the name (easy to know what it is). And all we need now is a simply way of setting the tags to our fields.
[code language="html"]
<input name="tags" id="tags" type="text" placeholder="(Optional)">
[/code]
OK, now when we have this, it is time for PHP / server side code to be added. Since we will be using Ziggeo PHP SDK, we will start by defining our keys for easy updates later on and for easy reference in the code.
[code language="php"]
define('APP_TOKEN', 'OUR_APP_TOKEN');
define('PRIVATE_KEY', 'OUR_PRIVATE_KEY');
[/code]
After that we make a simple check:
[code language="php"]
if(isset($_POST, $_POST['submitted']) && $_POST['submitted'] === 'submitted' && isset($_FILES)) {
[/code]
The check is needed otherwise you would try to upload the videos each time you open the page - which as there would not be any videos present on load, would cause you issues. Now if we did the HTML part of the page correctly we will see our videos in:
[code language="php"]
$_FILES['files']
[/code]
Now when itterating through the list of videos sent our way, we have few things to think about, so lets check how the code looks:
[code language="php"]
    for($i = 0; $i < $c; $i++) {
        $tmp_arguments = $arguments;
        $tmp_arguments['file'] = $_FILES['files']['tmp_name'][$i];
[/code]
As you can see when we are creating the path to video to be pushed to Ziggeo, we are using 'tmp_name', not 'name'. The reason for this is because tmp_name key holds the current location of your video file on your server - and that is the same that we need to push it to our Ziggeo account. And yes, you are correct, that [$i] at the end is there because all of the videos are listed in same order under $_FILES['files']['tmp_name'] so [0] would be first video [1] would be second, and so on, and we do the PHP work with the numbers for us using $i. All that is left now - yes that is correct - to create it:
[code language="php"]
$ziggeo->videos()->create($tmp_arguments);
[/code]
And that is it. You are now running a smooth bulk videos upload facility through the Ziggeo PHP SDK. If you like it - share it.
PREV NEXT