The Little Guy Posted April 26, 2013 Share Posted April 26, 2013 So, I have two database tables, and each one I would like to store files in. One of the tables will store fairly small PDF files, probably around 1MB and smaller. The other table would store zip files. What are your thoughts about doing this? Quote Link to comment https://forums.phpfreaks.com/topic/277339-saving-files-in-database/ Share on other sites More sharing options...
Psycho Posted April 26, 2013 Share Posted April 26, 2013 There are pros and cons to storing actual files in the database vs storing the files on the file system and just putting a path reference in the database. We cannot answer whether that is a good idea or not without knowing the reasoning behind storing them in the DB. From my experience, storing the files in the filesystem is typically the best approach unless you have some specific reasons not to. Quote Link to comment https://forums.phpfreaks.com/topic/277339-saving-files-in-database/#findComment-1426749 Share on other sites More sharing options...
The Little Guy Posted April 26, 2013 Author Share Posted April 26, 2013 I don't really know the pro or the cons, and it just seems like it is an easier approach than to store the files in the file system, and it seems like it would be a little more secure. Quote Link to comment https://forums.phpfreaks.com/topic/277339-saving-files-in-database/#findComment-1426750 Share on other sites More sharing options...
Psycho Posted April 26, 2013 Share Posted April 26, 2013 Well, it will definitely be slower since you will have to read the data from the database and then output the data appropriately. I'm not sure why you think it would think it is easier than just storing the path to a file. I tend to consider it a more complicated process. As for more secure, that is debatable. If you don't want the files publicly accessible you should be storing the files outside the root directory of the site. You can then use PH to read those files from the file-system and pass on to the user when they request them. Quote Link to comment https://forums.phpfreaks.com/topic/277339-saving-files-in-database/#findComment-1426753 Share on other sites More sharing options...
shlumph Posted April 26, 2013 Share Posted April 26, 2013 In my opinion, unless there's a strong reason to be storing the files in the DB, you should store them on the file system. That's what the file system was made for. The discussion here goes over pros/cons of storing files in the DB: http://programmers.stackexchange.com/questions/150669/is-it-a-bad-practice-to-store-large-files-10-mb-in-a-database Quote Link to comment https://forums.phpfreaks.com/topic/277339-saving-files-in-database/#findComment-1426755 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.