views:

915

answers:

5

A while a go I had to developed a music site that allowed audio files to be uploaded to a site and then converted in to various formats using ffmpeg, people would then download the uploaded audio files after purchasing them and a tmp file would be created and placed at the download location and was only valid for each download instance and the tmp file would then get deleted.

Now I am revisiting the project, I have to add pictures and video as upload content also.

I want to find the best method for storing the files,

option 1 : storing the files in a folder and reference them in the database

option 2 : storing the actual file in the database(mysql) as blob.

I am toying around with this idea to consider the security implications of each method, and other issues I might have not calculated for.

+9  A: 

See this earlier StackOverflow question Storing images in a database, Yea or nay?.

I know you mentioned images and video, however this question has relevance to all large binary content media files.

The consensus seems to be that storing file paths to the images on the filesystem, rather then the actual images is the way to go.

Ash
+3  A: 

I would go for storing files directly on the disk, and database holding only their ID/url.

This way accessing those files (that can be large, binary files) doesnt require any php/database operation, and it's done by the webserver directly.
Also it will be easier to move those files to another server if you'd want to.

Actually only one upside I can see atm of storing them in database is easier backup - you wanna backup your DB anyway, this way you'll have all data in one place and you can be sure that each backup is full (i.e. you don't have files on disk that aren't used by database entries; and you don't have image IDs in your database that point to nowhere)

kender
+1  A: 

I asked a similar question using Oracle as the backend for a Windows Forms application.

The answer really boils down to your requirements for backing up and restoring the files. If that requirement is important then use the database as it'll be easier (as you're backing up the database anyway, right? :o)

Andrew
+2  A: 

I would recommend storing as files and storing their locations in the database.

Storage the files in a database requires more resources and makes backing up/restoring databases slower. Do you really want to have to transfer lots of videos every time you do a database dump? File systems work very well for dishing out files, and you can back them up/sync them very easily.

Morphio
+2  A: 

I would go for the database option. I've used it on a number of projects, some very larger 100+GB. The storage implementation is key, design it poorly and your performance will be punished. See this example for some good implementation ideas:
Database storage allows more scalability and security.

DreamWerx