Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/227213-storing-pictures/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/227213-storing-pictures/#findComment-1172034
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/227213-storing-pictures/#findComment-1172036
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/227213-storing-pictures/#findComment-1172072
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.