Reputation: 19
I have uploaded a video into my MySQL DB and saved it under a BLOB column, now how do I load this data into my HTML / PHP webpage?
(I know saving video in a MySQL DB isn't recommended, but work with me on this. I'm doing this for learning purposes)
I've looked into doing this mostly with HTML, but I don't think inserting a directory through a PHP variable would work, as it's saved in my DB and not in a folder I can specify.
All help is appreciated.
Upvotes: 0
Views: 954
Reputation: 659
You have to grab it from db and save into a file on disk and then play it. (i did not test it myself, but it should work) after saving it into the file redirect browser to another page like this (you can pass the movie location in address or session or other ways). my example pass in url:
try this:
file_put_contents('/path/to/movie', $my_blob_movie);
header("Location: playmovie.php?location=/path/to/movie");
die();
and in playmovie.php get location as this:
$location = $_GET['location'];
and then play file....
Upvotes: 2
Reputation: 2387
Please clarify:
I've looked into doing this mostly with HTML, but I don't think inserting a directory through a PHP variable would work, as it's saved in my DB and not in a folder I can specify.
If you've got php and can create new scripts and upload them by FTP or whatever, you should be able to modify your upload script to write to a file.
Anyways, if it is uploaded using a web from, the file is already on your server.
In any case, you could write a php script to read the data from the database, and echo it out, after setting the HTTP Content-Type header:
// connect to DB and query for data
header("Content-Type: video/quicktime"); // Specify the mime type fr the specific video format
// output the video now
echo $videoblobdata;
See the Internet video mime types on Wikipedia:
http://en.wikipedia.org/wiki/Internet_media_type#Type_video
Upvotes: 1