Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed html5 video from php database

Tags:

html

php

cakephp

I'm making a site where users can search for and play videos (which are stored on our server). I have someone else doing a lot of the backend stuff but he doesn't know how to embed the videos in the webpage from the php database.

I've heard this can be a hard thing to do, but if someone could at least get me started I would very much appreciate it.

We're using CakePHP for backend stuff if that helps.

Thanks a lot

like image 323
Nathan B Avatar asked Feb 24 '26 23:02

Nathan B


1 Answers

I do not see the reason why the video must be stored in the database. If I were you, I'd store it in a dedicated folder, such as myApplication/static/videos/ and then just simply add a record to a videos database-table with related information about the video, which could be stuff like the following:

  • Author
  • Keywords
  • Description
  • Video-width
  • Video-height
  • Path to the source file on the server
  • Video type, mp4 etc

After that, it's pretty straight-forward: searching the database after keywords or a matching description - and upon a match simply generating the HTML5 markup:

// Gather information about the video
$video_data = get_video($id);

$markup = "<video width='". $video_data['source_width'] ."' height='". $video_data['source_height'] ."' controls='controls'>
  <source src='". $video_data['source_path'] ."' type='". $video_data['type'] ."' />
</video>";

Be sure to clean any input which comes from the user that's going to be stored in the database. This does NOT include the source path, which should be generated upon file upload, without the need of any user interaction, that is if you're going to allow users to upload files.

like image 85
Zar Avatar answered Feb 27 '26 14:02

Zar