Thursday, December 31, 2015

If you want to use YouTube API v3 from PHP, you will probably want to retrieve some kind of upload progress metric while your video is being transferred to YouTube.
If you check YouTube API documentation , especially videos.insert() function, you'll probably be disappointed. JavaScript version of file upload fully supports the upload progress retrieval, but PHP example has no notion of anything similar.

However, we can do something about it. Here's an idea:

If you carefully check the PHP example, you will see that current progress is easily obtainable in the while loop which sends your video chunk by chunk. We should grab this information, store it to a database or a file, and we're good to go.

Now, if we want to retrieve current video's upload progress, we just query our database using AJAX. AJAX opens a tiny PHP script which reads the current video upload information from database.
Here's a sample script: