Jump to content

Handling User Images


cmgmyr

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
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.