takn25 Posted February 9, 2011 Share Posted February 9, 2011 Hi, i would like to know what is the best method to store a picture. Currently what happens, is each user has a different avatar, which when uploaded comes in a folder called Avatar, in my website folder and is also stored as a BLOB in mysql. I would like to know is this ok to store all avatars in one folder or some other step should be used and if so could some one guide me to a good tutorial. As I would also like to make an option, where people could upload their pictures, is it safe to store pictures in the same folder for all users or some how create a different folder for each user. Quote Link to comment https://forums.phpfreaks.com/topic/227213-storing-pictures/ Share on other sites More sharing options...
KevinM1 Posted February 9, 2011 Share Posted February 9, 2011 I think the simplest way to do it is to save actual images on the disk, in folders, and to store their paths in a db. That way, you don't have to fuss with worrying about header info when you want to display them. Simply put their path as the src attribute of an img tag, and you're all set. For the rest, it's really a matter of how flexible you want it to be and how much up-front work you're willing to do to get it to work. That said, at the minimum, I think you should keep avatars separate from other images. Quote Link to comment https://forums.phpfreaks.com/topic/227213-storing-pictures/#findComment-1172034 Share on other sites More sharing options...
requinix Posted February 9, 2011 Share Posted February 9, 2011 Also stored in the database? There's no need for both: do just a file or just a BLOB. There are arguments for and against each one. In general: - Web developers prefer using files. They're easy to interact with and the web server itself can handle caching and displaying them. After a thousand or so you need to learn more about file systems and drawbacks. Some of them aren't designed for containing many files in one folder, but creating additional folders costs some disk space. - Database admins prefer using the database. With replication you can automatically distribute the files to other servers. Concurrency issues are more easily handled by a database, whereas with a file you often need to do some work by yourself. It also means the application logic and application data are completely separate; you could blow away files on a website and upload a new application without needing to worry about preserving uploaded files. If your web and database servers are separate then there's more issues: latency, connection limits, virtual/cloud servers... I, being a developer first and DBA second, prefer the first. Quote Link to comment https://forums.phpfreaks.com/topic/227213-storing-pictures/#findComment-1172036 Share on other sites More sharing options...
takn25 Posted February 9, 2011 Author Share Posted February 9, 2011 Do you know a good tutorial i can use to resize and reduce file size of an image ? After its been uploaded. This is because my uploaded avatars even when displayed in a different pixel size have the same file size of 500kb O_o this would load the page super slowly so some javascript file resize tutorial would be cool. Quote Link to comment https://forums.phpfreaks.com/topic/227213-storing-pictures/#findComment-1172072 Share on other sites More sharing options...
litebearer Posted February 9, 2011 Share Posted February 9, 2011 http://www.nstoia.com/sat/resize/ Quote Link to comment https://forums.phpfreaks.com/topic/227213-storing-pictures/#findComment-1172077 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.