Help with Video Upload with MySQL and PHP
I'm writing some PHP that will interact with MySQL to 1. upload and 2. display a Quicktime .mov file. I have done similar things with image formats quite easily, but this one is giving m开发者_JS百科e some issues. The upload is working in the sense that data is being inserted into the SQL table, and the client is getting something from my viewvideo.php script. However, the problem is that the data that the client receives isn't parsible as a Quicktime movie, meaning that somewhere along the line, something went wrong.. or maybe the data is encoded incorrectly? Here are the important segments of my two scripts:
The upload:
$name = $_FILES["file"]["tmp_name"];
$contents = file_get_contents($name);
mysql_query("INSERT INTO videos(id,data,title,description) VALUES($n,'$contents','$title','$description')");
The display:
$x = mysql_query("SELECT data FROM videos WHERE id=$id");
$results = mysql_fetch_array($x);
$data = $results[0];
header("Content-Type: video/quicktime");
echo $data;
exit;
My only hypothesis at the moment is that when I put the ' ' around $contents, it messes up the encoding of the string. The SQL server is temporarily down for maintenance, so I will have to wait to test this. Any help is appreciated.
Bad idea to do this with a Database. Blobs are just for binary data =< 256KB
. See here.
I would suggest you simply upload the .mov
-files using a
<input type="file" .../>
and then access the files directly via HTTP or stream them from the Server using something like a player-plugin (in Flash for example).
精彩评论