0

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 me 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.

codedude
  • 3
  • 2
  • How are you storing the binary MOV data in the database? The video data could be getting muddled up being written to the DB. Better off physically storing the file on the server and storing the path to the file in the DB. Cut down on DB overhead. – Jack Jul 08 '11 at 21:52
  • Imagine the file contains a `'`, what happens to your SQL query then? – hakre Jul 08 '11 at 21:53
  • I'm storing it in a BLOB. I wish I could store it in a file, but the admin doesn't allow me to have write access :( – codedude Jul 08 '11 at 21:53
  • Oh.. didn't think of that hakre.. unintentional SQL injection. Although I don't think the problem is there, because it inserts into the SQL correctly.. the only issue is the actual content that gets inserted. – codedude Jul 08 '11 at 21:54

1 Answers1

1

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).

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
  • Hey, thanks for the quick response. The hosting I'm currently using doesn't allow me to write files, only to use SQL. I suppose I could switch hosting, but I'd rather if I could find some kind of solution.. – codedude Jul 08 '11 at 21:56
  • I would suggest you switch the hoster if you're seriously planing to do that. Blobs are very slow for big files and will slow down your whole database. Also, I think the Script-Solution to your problem would be very ugly. – Lukas Knuth Jul 08 '11 at 22:01
  • EDIT: I think I'm going to switch hosting. Thanks to everyone for responding so quickly. – codedude Jul 08 '11 at 22:01