Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Uploads in seperate folders?

Featured Replies

Just a general question really I was wondering and google isn't spitting out much.

 

If you build a php upload system for pics, videos, files, whatever for different members to upload to a site - example our avatars on this site, AND the files have uniquely generated filenames (hex key etc.) to avoid duplication, is it better to :

 

1 : Have all files upload to one directory - example "/avatars/".

2 : Have php make a new folder for that member - example "Neil_32/avatars".

 

The one folder system will work, seeing as the filenames are unique and seems a lot easier to code, maintain etc. - but the problem is I'm worried about what happens when you get say 5000 files in one folder, even 10000, 20000 and so on.

The seperate folder system - well less files in each folder but you have the added complication of having to create / delete these folders in php - extra coding and what if you have 50000 members = 50000 folders?

 

Up until now I've usually done the one folder method, but suddenly started worrying about expandability - you have 1000 members each with 20 files - 20000 files in one subdirectory for example. Is that going to be a problem?

  • Author

Just to add an observation in - I notice when doing "image info" on my avatar that this forum seems to use the one folder method.

 

Any opinions?

I did something like this for a social network i've been working on heres the code

 

/*
Insert the users data into our USER_BASE
*/
   $sql = "INSERT INTO user_base(`first_name`,`last_name`,`email`,`password`,`photo`,`website`,`birthday`,`facebook`,`twitter`,`gender`,`side_video`,`activated`,`side_about`,`date_joined`,`time`,`ip`)
 VALUES('$f_name','$l_name','$email','" . secure($password) . "','$PHOTO','','$birthday','','','$gender','','0','',now(),'" . time() . "','$ip')
 ";
   $rel = $mysqli->db_query($sql);




/*
Create a folder for this member with a unique id number,
this folder will hold the members profile photo,photo albums ect..
*/


   /*
   Check to see if directory exist if it don't create a user directory
   */
    $id = mysqli_insert_id($mysqli->connect);
   if(!is_dir(UPLOAD_DIRECTORY."/$id" . "_" . "$f_name" . "_" . "$l_name")){
   mkdir(UPLOAD_DIRECTORY."/$id" . "_" . "$f_name" . "_" . "$l_name", 0755);
   //UPLOAD FILE
   move_uploaded_file($_FILES['photo']['tmp_name'],UPLOAD_DIRECTORY."/$id" . "_" . "$f_name" . "_" . "$l_name"."/".$_FILES['photo']['name']);
   }else{
   //UPLOAD FILE
   move_uploaded_file($_FILES['photo']['tmp_name'],UPLOAD_DIRECTORY."/$id" . "_" . "$f_name" . "_" . "$l_name"."/".$_FILES['photo']['name']);
   }

 

basically u use mkdir to create directories

Edited by webdesigner93

  • Author

Thanks, webdesigner.

You obviously think it's better to use the seperate folder method then?

Is there any particular reason for that or is it simply for the sake of a neater directory structure? Or perhaps eay access by say ftp to a particular member's pictures etc.?

Servers sometimes(?) have limits for the number of files per folder, though if you ran a dedicated server that would be under your control.

 

There are many options for file storage based on users:

 

Assign alphabetical folders for each username, eg /a /b /c etc

- you could go even deeper and use the first 2 characters of the name, eg /aa /ab /ac

- or even 4/5/6 characters

 

You could assign folders by user #ID

  • Author

Servers sometimes(?) have limits for the number of files per folder, though if you ran a dedicated server that would be under your control.

 

There are many options for file storage based on users:

 

Assign alphabetical folders for each username, eg /a /b /c etc

- you could go even deeper and use the first 2 characters of the name, eg /aa /ab /ac

- or even 4/5/6 characters

 

You could assign folders by user #ID

 

Thanks. Yeah that reinforces the way to go is seperate folders. I've in the meantime adjusted my site I'm building to name folders according to WebDesigners naming protocol (although I chose to go forename_surname_id) which seems ok to me. The reason I put the name first is so if I ever have to access a members folder in a hurry I can find it easier by ftp.

One thought struck me and I've just built this into mine - I'm keeping a dummy index file in a folder and copying that index file into all the members folders that are being generated when it makes the folders. I just thought maybe that was an idea to stop people just being able to view all the members files by hacking the url...

Thanks for the help, lads.

Thanks, webdesigner.

You obviously think it's better to use the seperate folder method then?

Is there any particular reason for that or is it simply for the sake of a neater directory structure? Or perhaps eay access by say ftp to a particular member's pictures etc.?

The reason i did it is about organization, does not make much since to mix every registers users photos,albums ect.. within one folder when u can create each user there own folder at sign up :)

  • Author

The reason i did it is about organization, does not make much since to mix every registers users photos,albums ect.. within one folder when u can create each user there own folder at sign up :)

 

Cool - +1 to you webdesigner (your first post) and I agree. I have recoded my site last night to accomodate this and it does indeed look more organised. Thanks for your help. And BlueDreamer too.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.