Title: Making directories for users?
Last modified: August 20, 2016

---

# Making directories for users?

 *  Resolved [ashton1993](https://wordpress.org/support/users/ashton1993/)
 * (@ashton1993)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/)
 * Heya, my website is [here](http://www.pixelsgame.org), I’m trying to make it 
   so that when a user registers on my site it’ll automatically create a directory
   for them ([http://pixelsgame.org/upload/USERNAME](http://pixelsgame.org/upload/USERNAME))
   which they can later use for uploading files to use in their posts, I’m using
   this code just after the account activation:
 * ‘<?php mkdir(“/upload/” . $user_info->user_login); ?>’
 * But the directory is not created upon activation and I receive this error:
 * ‘Warning: mkdir() [function.mkdir]: Permission denied in /hermes/bosweb/web096/
   b966/ipg.pixelsgamenet/wp-content/plugins/buddypress/bp-themes/bp-default/registration/
   activate.php on line 14’
 * I made sure that activate.php has permisions 0777 (everything turned on) but 
   still get the same error, don’t suppose anybody could help, also I know it’s 
   terribly thankless of me to ask but I’d be eternally grateful if you could also
   look at this [other unresolved issue](http://wordpress.org/support/topic/removing-pages-from-navbar-buddypress?replies=1)
   I’m trying to tackle. Thanks a lot for looking!

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [Harry](https://wordpress.org/support/users/harmck/)
 * (@harmck)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/#post-2601617)
 * What’s on Line 14 of activate.php?
 *  Thread Starter [ashton1993](https://wordpress.org/support/users/ashton1993/)
 * (@ashton1993)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/#post-2601620)
 * Oh sorry, it’s:
 * `<?php mkdir("/upload/" . $user_info->user_login); ?>`
 * Should have specified that was line 14
 *  [Harry](https://wordpress.org/support/users/harmck/)
 * (@harmck)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/#post-2601624)
 * Ah sorry, should have guessed myself.
 * Would it be a case of that /upload/ is the absolute path rather than the relative
   path?
 * And you’re trying to create a folder outside your designated area on a shared
   server?
 * Could you look at something like **wp_upload_dir()**?
 * [http://codex.wordpress.org/Function_Reference/wp_upload_dir](http://codex.wordpress.org/Function_Reference/wp_upload_dir)
 *  Thread Starter [ashton1993](https://wordpress.org/support/users/ashton1993/)
 * (@ashton1993)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/#post-2601639)
 * Heh, it was only when you posted that I realized I could change the upload directory
   rather than set up another FTP account to get decent looking links. Anyways I
   changed the code to:
 *     ```
       <?php $upload_dir = wp_upload_dir(); ?>
       <?php mkdir($upload_dir . "" . $user_info->user_login); ?>
       ```
   
 * Which doesn’t return an error _phew_, though neither does it create a directory
   for that user, I however came to the realization $user_info->user_login should
   only return a value when a user is logged in so I went on to write:
 *     ```
       24		<?php $upload_dir = wp_upload_dir();
       25		$dirname = $_POST[$user_info->user_login];
       26		$filename = "/$upload_dir/{$dirname}/";
       27
       28		if (file_exists($filename)) {
       29		echo ""; } else {
       30		mkdir($upload_dir . "" . $user_info->user_login);
       31    		}
       32		?>
       ```
   
 * Then chuck it in the theme header but got this error
 * `Warning: mkdir() [function.mkdir]: File exists in /hermes/bosweb/web096/b966/
   ipg.pixelsgamenet/wp-content/plugins/buddypress/bp-themes/bp-default/header.php
   on line 30`
 * Sorry if I’m just being silly.
 *  Thread Starter [ashton1993](https://wordpress.org/support/users/ashton1993/)
 * (@ashton1993)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/#post-2601690)
 * I’ve refined my code more though still having some dificulity, it should work
   but for some reason it doesn’t:
 *     ```
       <?php
       		global $current_user;
       		get_currentuserinfo();
   
       		$filename = "http://www.pixelsgame.org/upload/{$current_user->user_login}/";
   
       		if (file_exists($filename)) {
       		echo 'http://www.pixelsgame.org/upload/' . $user_info->user_login . ' supposedly already created'; } else {
       		echo 'http://www.pixelsgame.org/upload/' . $current_user->user_login . ' supposedly just created';
       		mkdir("$filename");
           		}
       		?>
       ```
   
 * It echoes “[http://www.pixelsgame.org/upload/ashton](http://www.pixelsgame.org/upload/ashton)
   supposedly just created” when I use it though doesn’t create the directory, any
   clues?
 *  [Harry](https://wordpress.org/support/users/harmck/)
 * (@harmck)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/#post-2601693)
 * Hi,
 * You can’t create a dir via a URL. Mkdir operates at a OS level to create the 
   directory.
 * From your above errors, your path on your server should be something like
 * `/hermes/bosweb/web096/b966/ipg.pixelsgamenet/wp-content/upload/`
 *  Thread Starter [ashton1993](https://wordpress.org/support/users/ashton1993/)
 * (@ashton1993)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/#post-2601708)
 * Awesome! It’s working perfectly now! Well thanks for all the help 🙂 do you think
   it’d be useful for me to post the code somewhere it can be used again by others
   or would I just be clogging things up?
 *  [Harry](https://wordpress.org/support/users/harmck/)
 * (@harmck)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/#post-2601710)
 * I’d be interested in having a look out of curiosity, so if you pastebin the code,
   and link it here, at least if someone is ever searching for the same solution
   they have a starting point.
 * Thanks,
    Harry
 *  Thread Starter [ashton1993](https://wordpress.org/support/users/ashton1993/)
 * (@ashton1993)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/#post-2601931)
 * Sorry, just ended up a bit busy and forgot about this but basically I was using
   inline upload and had modified it so that when a user uploaded a file it would
   go to their own directory (I’m using buddypress for a social networking rig) 
   except I discovered the plugin WP-Filebase which makes this obsolete >_<

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Making directories for users?’ is closed to new replies.

## Tags

 * [folder](https://wordpress.org/support/topic-tag/folder/)
 * [upload](https://wordpress.org/support/topic-tag/upload/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 2 participants
 * Last reply from: [ashton1993](https://wordpress.org/support/users/ashton1993/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/making-directories-for-users/#post-2601931)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
