jpeterson579's avatar

Proper way to structure and implement user's upload profile/and gallery images

I think this would be extremely helpful as I don't see much, if any documentation on allowing users to: Upload specific items such a profile images or just pictures in general to post to their feed? Create image gallery Upload in bulk?

Whats the proper way to do this? How would you structure the database? What about the folder structure where the images are actually stores?

Can we get a tutorial on this or can someone please advise on this topic? Thanks a ton

0 likes
3 replies
alsofronie's avatar

What you ask is a lot. For elegance, you need an Ajax file uploader. For image manipulation you need something like "orchestra/imagine". And more. For example, if you expect more than 10k users with profile pictures, do not store them in one folder. It gets very slow, even on ext3/ext4 (I mean the server). Another thing to consider is about balancing your available space (ram or hdd) with the speed you have (this goes directly to the question To Cache Or Not To Cache :).

For database structure I cannot help you. It's too application specific. To store the images, you have only two base choices: the public folder (a subfolder of it) or the storage folder. The difference is you will serve the images very quickly and with no memory consumption from your public folder, but you will lack the power of resizing/watermarking/protect the images, which you get if you choose the storage folder and make a controller to serve the images. Also, watch for memory here, it cat get messy really quick with a 10MB image.

jpeterson579's avatar

Thanks for the info. It does help me in pointing me in the right direction of what I should research to accomplish this.

And yes, Im sure it's a lot to explain which is the reason why it would be a great addition to the laracasts series section... Almost all web apps out there have some sort of feature like this, allowing users to upload images. I am sure many people would be able to benefit from some sort of tutorial on best practices and how to accomplish uploading and storing images in a number of ways...

1 like
austenc's avatar

@jpeterson579, my advice is to take it one (small!) step at a time. For example, get image (even single image) uploading working first... then build from there. A next step could be to store the path / link it to a given user in the database, then multi upload, then more, etc...

Post a new thread if you have a more specific problem and I'm sure everyone will be happy to help! It's easy to look at a feature (such as image upload/manipulation/etc...) and get overwhelmed when thinking of all the moving parts. Break the problem down and start simple , then build from there... good luck!

1 like

Please or to participate in this conversation.