cmgmyr Posted April 24, 2007 Share Posted April 24, 2007 So, I'm still building this "hot or not" site for my client and I was thinking about how to handle all of the user images. I was thinking of having all of the images in 1 directory...but after a while it will get pretty full. What are your thoughts about: 1. Keeping them all in one directory 2. Having an image directory with indevidual directories that are named the userid or username (user_images/1/my_image.jpg) 3. Having #2 broken down by first username initial. ex: username - admin (user_images/a/1/my_image.jpg), username - tom (user_images/t/1/my_image.jpg) 4. any other ideas? I'm trying to make this as easy to manage (and practical) in all aspects as possible. Please let me know your thoughts. Thanks, -Chris Link to comment https://forums.phpfreaks.com/topic/48397-handling-user-images/ Share on other sites More sharing options...
cmgmyr Posted April 24, 2007 Author Share Posted April 24, 2007 *bump* anyone? Link to comment https://forums.phpfreaks.com/topic/48397-handling-user-images/#findComment-237273 Share on other sites More sharing options...
redbullmarky Posted April 24, 2007 Share Posted April 24, 2007 is there any reason why the images directory being "full" is a bad thing? It wont get full to the point you can no longer write to it. I use a DB to keep track of all the stuff you'll find in the $_FILES array (mime, filename, etc) as well as a unique filename I generate for the file on upload. I generate my own names mainly to avoid any sort of clash, with something along the lines of: <?php $ext = '.jpg'; // this is retrieved from $_FILES['name'], not preset like this // repeat this loop until we have a unique filename do { // generate a random filename $filename = md5(rand()) . $ext; } while (file_exists(UPLOAD_DIR . $filename)); // $filename now can be inserted into the DB, and is also a unique filename ?> Link to comment https://forums.phpfreaks.com/topic/48397-handling-user-images/#findComment-237300 Share on other sites More sharing options...
cmgmyr Posted April 24, 2007 Author Share Posted April 24, 2007 It's not really a bad thing. I just thought that dividing it up might help performace a little bit...but maybe not. I also generate a new image name when they upload, this is a unique 16 char name. Link to comment https://forums.phpfreaks.com/topic/48397-handling-user-images/#findComment-237302 Share on other sites More sharing options...
gp177 Posted April 27, 2007 Share Posted April 27, 2007 I wrote a program somewhat similiar to this. We use it at my work do archive scanned documents. I found that keeping files in folders based on a customer's uid has been helpfull once or twice but is not mission critical by any means. One thing that I do like about it, is if our database was ever destroyed, the tape backups on site were destroyed, and our off site backup facility was nuked, I would still be able to grab documents directly off the hard drive... Link to comment https://forums.phpfreaks.com/topic/48397-handling-user-images/#findComment-239959 Share on other sites More sharing options...
steelmanronald06 Posted April 28, 2007 Share Posted April 28, 2007 Keep the images in a database. There is nothing wrong with it, and I find it a lot better to do it like that than to keep them in a directory. Link to comment https://forums.phpfreaks.com/topic/48397-handling-user-images/#findComment-240180 Share on other sites More sharing options...
roopurt18 Posted April 28, 2007 Share Posted April 28, 2007 Well, even if you keep the images in a DB you still need to decide how you'll store them on your file system. Each method (categorizing by user name / id or just dumping into a single directory) has its advantages and disadvantages. Link to comment https://forums.phpfreaks.com/topic/48397-handling-user-images/#findComment-240186 Share on other sites More sharing options...
cmgmyr Posted April 28, 2007 Author Share Posted April 28, 2007 yes, that is the only thing that i'm looking for...the physical storage of the images. All of the images will be in a database. Thanks for all of the input so far. Link to comment https://forums.phpfreaks.com/topic/48397-handling-user-images/#findComment-240312 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.