Better way to store large files in a MySQL database?

tururu

New Member
I have a PHP script that you can upload very large files with (up to 500MB), and the file's content is stored in a MySQL database. Currently I do something like this:\[code\]mysql_query("INSERT INTO table VALUES('')");$uploadedfile = fopen($_FILES['file']['tmp_name'], 'rb');while (!feof($uploadedfile)) { $line = mysql_escape_string(fgets($uploadedfile, 4096)); mysql_query("UPDATE table SET file = CONCAT(file, '$line') WHERE something = something");}fclose($uploadedfile);\[/code\]This of course does a bloody lot of sql queries.I did that rather than something like\[code\]$file = file_get_contents($_FILES['file']['tmp_name']);mysql_query("INSERT INTO table VALUES('$file')");\[/code\]because that would use up however much memory the file was, and it seemed better to do more sql queries than to use 500 mb of memory.
However, there must be a better way. Should I go ahead and do it the file_get_contents way or is there a better way than CONCAT, or is the way I'm doing it now the lesser of all evils?
 
Back
Top