Dealing with file uploads in a web environment is a real pain. I've certainly been there. Everything else the user sends you is so well behaved - just a bunch of text you can stick in a table and be done with it! It's very tempting to think that you can get away with treating file uploads the same way, but I think it's a mistake to go that way.
MySQL is not a distributed file-system and it's not tuned to handle huge files like this. This problem inserting the file without loading it into memory is really just the start of your woes. How will you get the file out again? How will you do backups of your DB now that mysqldump is producing dumps that contain every file any user ever uploaded? Will you re-invent directories at some point? Permissions too? What will you do when you want to process the uploaded files with an external tool (resizing images, transcoding video, etc)?
It's not too late to setup an NFS server! It's not as hard as you probably think, and once you have one setup you'll find other uses for it (configuration, shared code installs, etc) and stop leaning on your DB so hard.
-sam
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.